我是“jQuery ajax”的新手,我正在使用 ajax 将请求发送到服务器。我正在发送数据,即 no、name、class、age 作为正常参数。我的要求是,我想以 JSON 格式发送数据。我的代码是,
function fun1() {
$.ajaxSetup({
jsonp: null,
jsonpCallback: null
});
$.ajax({
type: 'POST',
url: 'register.action',
dataType: 'json',
data: {
no: document.getElementById("id1").value,
name: document.getElementById("id2").value,
clas: document.getElementById("id3").value,
age: document.getElementById("id4").value
},
success: function (data) {
printStudentDetails(data);
},
error: function () {
alert("failure");
}
});
}
我的服务器端资源是java。