@Eric I think I get it. So I assume -- again, using this example -- if your server returned json content AND the appropriate header, you were expecting json and you did NOT pass 'json' as the 4th param to $.post(), then data.name etc would be undefined. Right?
And conversely, if your server returned JSON but failed to indicate the content-type as json but you DID tell $.post() it's JSON, then .... bla bla bla it would work. Right? I should test it and see for myself, I know. @maggus.staab Thanks for the tip, I will have a look. On Feb 3, 11:52 am, Eric Garside <gars...@gmail.com> wrote: > Basically, the 4th parameter tells jQuery what to do with the response > data. > > JSON indicates you're expecting a JSON string as the post response. > 'xml' indicates you want the return text parsed as XML (true AJAX). > 'html' means it's coming in as, I think a jquery object. And text is > just text. Those are the basic ones I've seen used most of the time. > > On Feb 3, 11:15 am, "maggus.staab" <markus.st...@redaxo.de> wrote: > > > at api.jquery.com there is a well documented version.. > > > @api doc devel: > > would be nice if we can link to a specific api page... > > > On 3 Feb., 16:55, Professor B <vtbludg...@gmail.com> wrote: > > > > I have stared at the docs for a while and still don't understand the > > > purpose of the option 4th parameter > > > in the $.post() method. The wording and examples > > > athttp://docs.jquery.com/Ajax/jQuery.postseemodd. E.g: > > > > [quote] > > > Gets the test.php page contents which has been returned in json format > > > (<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>) > > > > $.post("test.php", { func: "getNameAndTime" }, > > > function(data){ > > > alert(data.name); // John > > > console.log(data.time); // 2pm > > > }, "json"); > > > [/quote] > > > > We submit a POST request to test.php with parameter func = > > > 'getNameAndTime' -- presumably for test.php's benefit so it can call > > > that function, right? I think that's a little obscure in this example. > > > > Then we have an anonymous callback function that fires upon completion > > > of a successful xhr request, its input parameter being 'data' which is > > > the response body of the xhr object, right? > > > > In this instance, 'data' is an object -- a hash, an associative array, > > > what have you. So if that's what it is, then it is what it is, so to > > > speak. Is it not? I would expect that internally, JQuery would detect > > > the content-type header indicating JSON and eval the xhr response body > > > automatically. The server side would (and should) be responsible for > > > sending the proper content-type. > > > > Am I to understand that in this example test.php might as well send > > > plain old text/html, and the type hint "json" instructs JQuery to eval > > > it?