davej, on 15 April 2012 - 05:24 PM, said:
What I'm interested in is what the raw data looks like. Will the browser ignore it because it doesn't start with <html>? Or will the browser display it? Or will the browser report an error?
If you've requested it with AJAX - none of the above.
The raw data is available from the "responseText" property of XMLHttpRequest, once the request is actually performed. Whatever you've written will be available there in exactly the way you wrote it. If you write "<html>", the value of responseText will be "<html>". If you write "{}", responseText will be "{}", etc.
It's up to you, within JavaScript, to actually interpret that "{}" to mean either the text "{}", or something else, such as JSON. If JavaScript is not available, you wouldn't send a request to begin with, and if no callback was specified, the response is never interpreted, so whatever you had in the response would have no effect at all.
If, from your browser, directly, you open up a PHP file that outputs JSON, what you see will depend on the Content-Type header.
The greatest difficulty in programming is not in finding answers, but in asking yourself the right questions. -- If nobody has said it before, then I'd like to take credit of thinking this up (during summer of 2010).
"Complex problems often have the simplest solutions" -- Not sure who said that first.
=== My projects (all feedback welcomed) ===
XML_XSLT2Processor(0.5.3) - perform XSLT 2.0 transformations in PHP.
PEAR2_Net_Transmitter(1.0.0a3) - reliable sockets.
PEAR2_Cache_SHM(0.1.1) - persistent data storage wrapper.
=== Useful tools ===
NetBeans - full featured PHP IDE, as well as a decent code editor for other things.
Fiddler2 - The best free HTTP debugger. Performance tuning, security check, integrity check, custom requests and more, all made easy.
Gobby - That's
NOT my Nickname! Look at the topic.