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.postseem odd. 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?