簡體   English   中英

jQuery ajax請求數據未發送

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM