I am trying to append data that gets returned from a ajax call. I have the ajax call working correctly. However the data returned is one giant character array. I am using grails MVC, and the value I am returning is a ArrayList. I want to be able to run a for loop that will go through the items. But in order to do that I want to know if there is a way to convert 'data' into an array. The output is shown below.
我试图附加从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 return data value:
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']
]
1 个解决方案
#1
0
Are you looking to have an array of objects? If so, you may need to alter your server's getAllActivitiQueue method to return the data like this:
你想要一个对象数组吗?如果是这样,您可能需要更改服务器的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'}
]
see this jsfiddle
看到这个jsfiddle
Alternately, you could try using JSON.parse
或者,您可以尝试使用JSON.parse
#1
0
Are you looking to have an array of objects? If so, you may need to alter your server's getAllActivitiQueue method to return the data like this:
你想要一个对象数组吗?如果是这样,您可能需要更改服务器的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'}
]
see this jsfiddle
看到这个jsfiddle
Alternately, you could try using JSON.parse
或者,您可以尝试使用JSON.parse