Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

Just a little quirk I've come accross and I think I must be missing something so would like some clarification to further my understanding of what's going on with my code.

I post a form via jQuery AJAX, the form is processed by PHP and in the PHP I have the line

return $status;

$status is an array containing several values i.e $status['username'] = 'admin'

The AJAX datatype is set to 'JSON' but I am not using echo json_encode($status); in my PHP but everything is still working and my $status array is processed by jQuery upon AJAX success. Why is this? I thought json_encode would be required but it seems it isn't.

share|improve this question
    
Such a mystery. Not encoded array and without echo, are you sure everything works? – vikingmaster Feb 17 '13 at 17:43
    
Yea it definitely works, I can get any of the values in $status to pop up in an alert message in jQuery. – David Healey Feb 17 '13 at 17:48
    
Without the context 'where' the output is actually echoed/output this will remain a mystery and we can only guess – thaJeztah Feb 17 '13 at 17:55
    
always use json_encode when trying to parse it with javascript – self Feb 17 '13 at 17:55
    
It would also help if you show us the array and function used to return $status – self Feb 17 '13 at 17:56

2 Answers 2

json_encode use but out of this function that you see the

  return $status;

on it for understand it you can see developer tools in browser then find ajax request, see content response . for find json_encode search for location of calling this function.

share|improve this answer

Apologies I had made a daft mistake, my function was indeed returning $status, but it was returning it to another function which performed the json_encode. Mystery solved :) Thanks.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.