I see you are using jquery, if you want data to come back to you as a json object you need to do 1 of 2 things add header("Content-Type: application/json") to your php file, this will tell jquery to convert it to a json object instead of as text Add a forth parameter to your $. Post $. Post('/ajax-database.
Php', function (data) { console. Log($. ParseJSON(data)); $.
Each(data, function (key, value) { console. Log(value); }); }, "json") that will tell jquery to call your error handler if its NOT json, like if your php code fails and outputs html instead. You really should use $.
Ajax, I have no idea why anyone uses $. Post, you can't do ANY meaningful error handling.
I see you are using jquery, if you want data to come back to you as a json object you need to do 1 of 2 things. Add header("Content-Type: application/json") to your php file, this will tell jquery to convert it to a json object instead of as text Add a forth parameter to your $. Post, $.
Post('/ajax-database. Php', function (data) { console. Log($.
ParseJSON(data)); $. Each(data, function (key, value) { console. Log(value); }); }, "json"); that will tell jquery to call your error handler if its NOT json, like if your php code fails and outputs html instead.
You really should use $. Ajax, I have no idea why anyone uses $. Post, you can't do ANY meaningful error handling.
1 was about to post when I saw yours – Philar Nov 27 '10 at 19:34 If a request with jQuery.post() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method. - api.jquery. Com/jQuery.
Post – ajreal Nov 27 '10 at 19:38 Yes I know, I just consider it bad practice to globally handle errors in that respect, as each different script could and probably will error differently. – Jeremy Walton Nov 27 '10 at 19:42 In that case, you can't do ANY error handling is not true. – ajreal Nov 27 '10 at 19:49 Changed it just for you.
– Jeremy Walton Nov 27 '10 at 20:40.
JSON is strings. If you want to be able to iterate over it then you need to decode it.
Yeah but the problem is that it's not json. It it's got square brackets. – Mark Nov 27 '10 at 19:19 Yes, it is.
The top value is not required to be an object. – Ignacio Vazquez-Abrams Nov 27 '10 at 19:20 @Mark: remember just mean Array, and all array's in javascript ARE objects, they have prototypes. – Jeremy Walton Nov 27 '10 at 19:29 Specifically, the top value in JSON can be any of the things in the value construct here: json.Org – Ignacio Vazquez-Abrams Nov 27 '10 at 19:30 The question was asking how to decode the string I got.
I can run parseJSON on the string, and the values inside the fake array became json objects, but I still couldn't iterate over the entire array. The fake array became a real object after I set the datatype. I'm pretty confused by this answer.
– Mark Nov 27 '10 at 19:38.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.