jquery ajax的问题​​获取函数响应数据 [英] Problem with jquery ajax get function response data

查看:70
本文介绍了jquery ajax的问题​​获取函数响应数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我最近突然遇到了以下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆