簡體   English   中英

如何打印從AJAX調用返回的數據

[英]How to print data that gets returned from AJAX call

我正在嘗試附加從ajax調用返回的數據。 我的ajax調用正常工作。 但是,返回的數據是一個巨型字符數組。 我正在使用grails MVC,返回的值是ArrayList。 我希望能夠運行將遍歷所有項目的for循環。 但是為了做到這一點,我想知道是否有一種方法可以將“數據”轉換為數組。 輸出如下所示。

function getAllActivitiItems() {
    console.log ("Starting function");
    $.ajax({
        url: '${g.createLink(controller: 'Activiti', action: 'getAllActivitiQueue')}',
        type: 'POST',
        success: function(data) {
            console.log("Made it! "+data);
        },
        error: function(data) {
            console.log(data);
        }
    });
}

AJAX返回數據值:

[
  ['userId':'FP301', 'taskId':'1', 'storeKey':'001E0', 'callKey':'12634'], 
  ['userId':'TS206', 'taskId':'2', 'storeKey':'00IAC', 'callKey':'12758'], 
  ['userId':'SN304', 'taskId':'3', 'storeKey':'00IAC', 'callKey':'09843']
]

您是否正在尋找對象的數組? 如果是這樣,您可能需要更改服務器的getAllActivitiQueue方法以返回數據,如下所示:

[
    {'userId':'FP301', 'taskId':'1', 'storeKey':'001E0', 'callKey':'12634'}, 
    {'userId':'TS206', 'taskId':'2', 'storeKey':'00IAC', 'callKey':'12758'}, 
    {'userId':'SN304', 'taskId':'3', 'storeKey':'00IAC', 'callKey':'09843'}
]

看到這個jsfiddle

或者,您可以嘗試使用JSON.parse

暫無
暫無

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

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