I have a script which outputs JSON when needed. PHP sets headers to JSON and JSON encodes an object..
On the JS side, $.getJSON received it and all is dandy.
The problem is when my PHP outputs plain text (which is a case I have to deal with).
The bigger problem is, as much as I’d like to work a code to check for type of output from PHP side, getJSON will not trigger the callback function unless it receives a JSON type output.
So if my PHP script outputs an error code, (not encoded into JSON routine) the JS wont react..
I needed JS to react in a certain way based on PHP’s output type..
I tried to do the .get or .post JS functions but likewise, when my PHP output JSON, the callbacks for these don’t get triggered/fired.
Have you looked at .done() and .fail() ?
… also, here’s some JS code to validate JSON …