简体   繁体   English

JQUERY getJSON / Ajax响应未处理

[英]JQUERY getJSON / ajax response not being processed

I am sending a json request to a server as below: 我正在向服务器发送json请求,如下所示:

$.getJSON("prod_search.php?type=getCustInfo&custID="+custID, function(json) {
  alert(json.address);
  $("#invAddress").html(json.address);
  $("#currency").html(json.second);
});

Using firebug to check, the response is below, but the alert shows 'undefined' and no values are inserted. 使用Firebug进行检查时,响应如下所示,但警报显示“未定义”,并且未插入任何值。

[{"address":"abc123","second":"ABC"}]

Any ideas? 有任何想法吗?

Use 采用

json=json[0]

at first in the callback. 首先在回调中。 You receive an array, and the object you like to access is the first(and only) item inside this array. 您收到一个数组,并且您要访问的对象是此数组中的第一个(也是唯一的)项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM