0

I am sending a json request to a server as below:

$.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.

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

Any ideas?

1
  • are the [] brackets added for readability or anything? because it looks like its an array with an object in it, does alert(json[0].address) work? Commented Oct 5, 2010 at 8:49

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

or return {"address":"abc123","second":"ABC"}
Guys, you are both legends. I spent all day yesterday staring at this!
i agree with this answer. [] <-- array {} <-- object so a [{}] would return an array with an object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.