I perform an Ajax call and when done, I call
.done(function (response) {
$('#results').append(response);
});
The output from this is something like
array(5) { [0]=> string(24) "[email protected]" [1]=> string(8) "Approved" [2]=> string(1) "F" [3]=> string(8) "Rejected" [4]=> string(6) "ABC123" }
That would suggest that I could then do something like the following
.done(function (response) {
$('#results').append(response[0]);
});
If I do this though, my output is the single character 'a'. I have tried .html, .text etc all with the same result.
Is there any reason this may be happening?
asked Jun 18, 2015 at 14:36
Nick Price
9632 gold badges13 silver badges26 bronze badges
1 Answer 1
The reason is PHP file has:
var_dump($whatever);
Change it to:
json_encode($whatever);
answered Jun 18, 2015 at 14:38
Praveen Kumar Purushothaman
167k27 gold badges215 silver badges262 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
emerson.marini
PHP? Where did you see this in the OP's question?Praveen Kumar Purushothaman
@MelanciaUK PHP's
var_dump only returns output like this!emerson.marini
I see... So it's something implied.
Felix Kling
@MelanciaUK: The
response gives it away.emerson.marini
Too many years with just
ASP.NET. Can't remember a thing of PHP. |
lang-js
responseis still a string. It seems you usedprint_r($foo)to output the array. There is no easy way to parse this in JS. You should return JSON instead.