簡體   English   中英

jQuery .ajax調用在成功函數調用中返回undefined或null

[英]jQuery .ajax call returning undefined or null in the success function call

我有以下jQuery ajax調用:

executeAllAjaxCalls:function() {
    if (WALMART.jQuery.ajaxCalls.length) {
        var dataPassed = "ajaxCalls="+WALMART.jQuery.ajaxCalls;        

        WALMART.jQuery.ajax({   
            url: WALMART.jQuery.ajaxFrameworkUrl                     
            , data: dataPassed
            , dataType: WALMART.jQuery.jsonResponseType   
            , type: 'POST'   
            , success: WALMART.jQuery.AjaxObject_Consolidated.processConsolidatedData
        });
    }       
}

成功后返回到函數調用中的數據是不確定的。

這是在ajax調用成功時調用的函數:

processConsolidatedData:function(result) {
    alert("1234"+result);
    var responseData = eval('(' + result.responseText + ')');
    if (typeof responseData !== '') {
        for (resp in responseData) {
                ALMART.jQuery(document).ready(responseData[resp].CallbackFunction);             
        }
    }
}

當后端c:out上的struts操作為有效的JSON對象時,響應為何為null或未定義。 感謝任何技巧或指針,因為我對jQuery非常陌生。

我認為您的代碼中有錯誤...

    for (resp in responseData) {
            ALMART.jQuery(document).ready(responseData[resp].CallbackFunction);             
    }

我認為您提到:

    for (resp in responseData) {
            WALMART.jQuery(document).ready(responseData[resp].CallbackFunction);             
    }

除非必要,我還將使用jQuery.parseJSON代替'eval'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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