[英]jQuery ajax request data not send
i am trying some idea on a ajax send,but i can't find why this code can't not send any parameter to jsp and thorw the nullpointerException. 我正在尝试关于ajax发送的一些想法,但是我找不到为什么此代码无法将任何参数发送给jsp并阻止nullpointerException的原因。
I fix my code here,thanks for reponse. 我在这里修复我的代码,感谢您的答复。
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);
});
});
Change your data
to: 将
data
更改为:
data: { dataVar : dataVal }
and your dataType
to 和您的
dataType
到
dataType: isJSON ? "JSON" : "text
They both don't accept functions. 他们俩都不接受功能。
data
accepts plain object or string and dataType
accepts only string data
接受纯对象或字符串, dataType
仅接受字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.