0

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
1
  • response is still a string. It seems you used print_r($foo) to output the array. There is no easy way to parse this in JS. You should return JSON instead. Commented Jun 18, 2015 at 14:38

1 Answer 1

2

The reason is PHP file has:

var_dump($whatever);

Change it to:

json_encode($whatever);
answered Jun 18, 2015 at 14:38
Sign up to request clarification or add additional context in comments.

6 Comments

PHP? Where did you see this in the OP's question?
@MelanciaUK PHP's var_dump only returns output like this!
I see... So it's something implied.
@MelanciaUK: The response gives it away.
Too many years with just ASP.NET. Can't remember a thing of PHP.
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.