[英]jQuery ajax request data not send
我正在嘗試關於ajax發送的一些想法,但是我找不到為什么此代碼無法將任何參數發送給jsp並阻止nullpointerException的原因。
我在這里修復我的代碼,感謝您的答復。
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
僅接受字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.