I have come across this snippet in the jquery post documentation and i am not sure what it does
$.post("test.php", { "func": "getNameAndTime" },
function(data){
console.log(data.name); // John
console.log(data.time); // 2pm
}, "json");
My thinking is that test.php has a function getNameAndTime(),is this the meaning of it?.If so is this some kind of javascript pattern?.
That means, this script is making an asynchronous
POSTcall totest.phppage and passing a parameter calledfuncwith valuegetNameAndTime. then it is receiving the response from this ajax server page in a variable calleddata. I guess the respone is inJSONformat. So in thecallbackfunction, It is accessing thenameandtimepart from the JSON response and making a call to the console.debug function so that it will be printed in the firebug console.The JSON may look like this
There may be additional items in the JSON. But for sure our code is expexting a
nameandtimeelementsYou may refer the below resources to get a good understanding of what each item does
$.post : Load data from the server using a HTTP POST request.
JSON : Javascript Object Notation– A lightweight data-interchange format