jquery ajax的问题获取函数响应数据 [英] Problem with jquery ajax get function response data
问题描述
大家好,
我最近突然遇到了以下AJAX片段的问题。
Hi all,
I'm facing an issue all of a sudden recently with the below AJAX snippet.
var obj = $.get(serviceUrl + "?q=" + keyword, function (data, status) {
if (status == 'success') {
$.each(data, function (index, item) {
returnString = item.keymatchterm;
returnString = encodeURIComponent(returnString);
});
}
}, "json");
样本响应输出:data =[{keymatchterm:Axis}],status =success
当使用$ .each时,数据会被迭代为
inde x = 0,item =[而不是 {keymatchterm:Axis}
我是无法找出导致此问题的原因。
对此有任何建议都会有很大帮助。
提前致谢< br $> b $ b
我尝试过:
最初数据类型未包括在内作为$ .get方法的一部分。我后来添加它只是为了确保预期的数据类型是JSON。我不确定是否应该明确使用JSON Parse()方法来解析响应。响应已经在JSON中。
Sample Response Output: data = "[{"keymatchterm":"Axis"}]", status = "success"
When using the $.each, the data is getting iterated as
index = 0, item = "[" rather than {"keymatchterm":"Axis"}
I'm not able to find out what could be the reason for this issue.
Any suggestions on this would greatly help.
Thanks in advance
What I have tried:
Initially the data type was not included as a part of $.get method. I later added it just to make sure the expected data type is JSON. I'm not sure whether should we explicitly use JSON Parse() method to parse the response. The response is already in JSON.
推荐答案
.get(serviceUrl + ?q = + keyword, function (数据,状态){
if (status == ' success'){
.get(serviceUrl + "?q=" + keyword, function (data, status) { if (status == 'success') {
.each(data, function (index,item){
returnString = item.keymatchterm;
returnString = encodeURIComponent(returnString);
});
}
}, json) ;
.each(data, function (index, item) { returnString = item.keymatchterm; returnString = encodeURIComponent(returnString); }); } }, "json");
示例响应输出:data =[{keymatchterm:Axis}],status =成功
当使用
Sample Response Output: data = "[{"keymatchterm":"Axis"}]", status = "success"
When using the
.each时,数据将被重复为
index = 0,item =[而不是 {keymatchterm:Axis }
我无法找出导致此问题的原因。
任何建议这将有很大的帮助。
提前谢谢
我尝试过:
最初数据类型未包含在
.each, the data is getting iterated as
index = 0, item = "[" rather than {"keymatchterm":"Axis"}
I'm not able to find out what could be the reason for this issue.
Any suggestions on this would greatly help.
Thanks in advance
What I have tried:
Initially the data type was not included as a part of
的一部分中
这篇关于jquery ajax的问题获取函数响应数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!