我所常用的ajax调用格式

ajax:

$.ajax({
    type: "post",
    datatype: "json",
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    url: "/ProductTypeAndCat/AddType",
    async: true,
    cache: false,
    data: { typeName: typeName },
    success: function (data) {
        if (data.F == 1) {
            alert(data.M);
            return;
        }

        alert("添加成功!");
        location.href = "/Admin/ProductType";
    },
    error: function (xhr, status, error) {
        alert(error);
    }
});

form提交,利用此插件(http://jquery.malsup.com/form/):

$('#frmDemo').ajaxSubmit({
    type: "post",
    url: "/ProductTypeAndCat/AddCategory",
    success: function (data) {
        if (data.F == 1) {
            alert(data.M);
            return;
        }

        alert("添加成功");
        location.href = "/admin/createProductCategory";
    },
    error: function (xhr, status, err) {
        alert(err);
    }
});

posted @ 2015-08-19 12:08  陆敏技  阅读(381)  评论(0编辑  收藏  举报
Web Counter
Coupon for Contacts