I was looking at this post: SyntaxError: Unexpected token o in JSON at position 1
Exactly my issue. But when I try to remove the parse, I then get the error: Cannot read property '0' of undefined.
Here is my original excerpt:
$.ajax({
type:"POST",
url:"getuser.php",
data: 'person='+str,
success: function(response){
var result = JSON.parse(response);
var data = result.rows;
$("#id").val(data[0].id);
$("#card").val(data[0].card);
$("#name").val(data[0].name);
$("#type").val(data[0].type);
$("#cabin").val(data[0].cabin);
$("#birthdate").val(data[0].birthdate);
}
});
My incoming data from getuser.php is:
{"id":"16758","card":"221","name":"Spongebob","type":"Staff","cabin":"24","town":"Bikini Bottom","birthdate":"07/14/1986"}
So if I remove the parse and make it:
success: function(response){
var data = response.rows;
It gives me the property 0 of undefined.
Here is a fiddle excluding the request from php: http://jsfiddle.net/vzwbop2t/
Any ideas? I am looking to edit a user, so I need the database values to populate the inputs in the form, so then any modifications, and it's saved back to the user.
Thanks.