Javascript jQuery ajax请求数据未发送
我正在尝试一些关于ajax发送的想法,但是我找不到为什么这段代码不能向jsp发送任何参数并thorw nullpointerException 我在这里修复了我的代码,谢谢回复Javascript jQuery ajax请求数据未发送,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试一些关于ajax发送的想法,但是我找不到为什么这段代码不能向jsp发送任何参数并thorw nullpointerException 我在这里修复了我的代码,谢谢回复 var dfd = { resolve : function (res) { $("#Div123").html(res); } }; function getAjaxResponse(page, responseType, dataVar, dataV
var dfd = {
resolve : function (res) {
$("#Div123").html(res);
}
};
function getAjaxResponse(page, responseType, dataVar, dataVal, dfd) {
var dataObject = $.parseJSON('{"'+ dataVar +'":"'+ dataVal +'"}');
$.ajax(page, {
type: 'POST',
dataType: responseType,
data: dataObject,
success: function (responseData) {
dfd.resolve(responseData);
}
});
}
$(document).ready(function(){
$("#submit").click(function(){
getAjaxResponse("ajaxreponse.jsp", "text", "aa", "yes", dfd);
});
});
将
数据更改为:
data: { dataVar : dataVal }
以及您的数据类型
dataType: isJSON ? "JSON" : "text
它们都不接受函数
数据
接受普通对象或字符串,而数据类型
只接受字符串数据类型和数据选项不接受函数您必须调用函数并使用返回值:使用函数(){}(),而不是可能重复的感谢Amit Joki,您解决了我的问题。