jQuery中Ajax的使用

1.发送json数据

// 提交表单数据到后台处理
$.ajax({
type: “post”,
data: $(‘#form_data’).serialize(),
contentType: “application/json”,
url: “/Home/Submit”,
beforeSend: function () {
// 禁用按钮防止重复提交
$(“#submit”).attr({ disabled: “disabled” });
},
success: function (data) {
if (data == “Success”) {
//清空输入框
clearBox();
}
},
complete: function () {
$(“#submit”).removeAttr(“disabled”);
},
error: function (data) {
console.info(“error: ” + data.responseText);
}
});

2.发送get请求

// 提交表单数据到后台处理
$.ajax({
type: “post”,
data: studentInfo,
contentType: “application/json”,
url: “/Home/Submit”,
beforeSend: function () {
// 禁用按钮防止重复提交
$(“#submit”).attr({ disabled: “disabled” });
},
success: function (data) {
if (data == “Success”) {
//清空输入框
clearBox();
}
},
complete: function () {
$(“#submit”).removeAttr(“disabled”);
},
error: function (data) {
console.info(“error: ” + data.responseText);
}
});

3.发送post请求

 

$.post(
‘//localhost:8080/user_info/update/batch_commit’,
{cardNums: str},
function (resp) {
layer.alert(resp.msg);
tableReload.reload();
}, ‘json’
);