jQuery ajax请求数据未发送 [英] jQuery ajax request data not send
本文介绍了jQuery ajax请求数据未发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试关于ajax发送的一些想法,但是我找不到为什么这段代码无法将任何参数发送给jsp并阻止nullpointerException.
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.
我在这里修复了我的代码,感谢您的答复.
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);
});
});
推荐答案
将您的data
更改为:
data: { dataVar : dataVal }
和您的dataType
dataType: isJSON ? "JSON" : "text
它们都不接受功能.
data
接受纯对象或字符串,而dataType
仅接受字符串
data
accepts plain object or string and dataType
accepts only string
这篇关于jQuery ajax请求数据未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文