0
var data  = xhr.responseText;

When I output this console.log(xhr.responseText). Below is my output

["{id:1,name\":\"JOHN\",\"city\":\"null\"}"
,"{\"id\":2,\"name\":\"MICHEAL\,\"city\":\"null\"}"]

How do I get id, name. I tried like this data.id but I get this error

jquery JSON.parse: unexpected end of data.

Update

I am using code igniter with data mapper so my data mapper is giving that json response. Do you know, how I can resolve it.

JJD
  • 50,076
  • 60
  • 203
  • 339
user2261231
  • 109
  • 2
  • 13

1 Answers1

0

You've already been told what the problem is in the comments: the JSON generated by the server is invalid. You are probably not using a library to encode your JSON, don't ever encode it by hand.

Your JSON should probably look like the following (when pretty printed) http://jsfiddle.net/7FKWr/

[
  {"id": 1, "name": "JOHN", "city": null},
  {"id": 2, "name": "MICHEAL", "city": null}
]
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
  • :I am using code igniter with data mapper so my data mapper is giving that json response.Do you know, How I can resolve it. – user2261231 Apr 11 '13 at 16:35
  • 1
    @user2261231 I don't mean to be rude, but how do you expect someone to help you if you don't show your code? Don't spam all the commenters – Ruan Mendes Apr 11 '13 at 16:51
  • :http://stackoverflow.com/questions/15954174/code-igniter-with-data-mapper-giving-in-valid-json – user2261231 Apr 11 '13 at 16:55