Rushino
Rushino

Reputation: 9505

How is used the 'func' in data parameter of get in jquery ajax?

Ive looked at the example of get in jquery website. The last example show this..

$.get("test.php", { "func": "getNameAndTime" },
   function(data){
     alert(data.name); // John
     console.log(data.time); //  2pm
   }, "json");

I was wondering what is the "func" part..how it is used and what you can do with it ?

To me it seem of calling the function getnameAndTime somewhere but where ?

Thanks.

Upvotes: 0

Views: 149

Answers (2)

Naftali
Naftali

Reputation: 146310

That means in php that the $_GET param will look like this:

$_GET = array (
   'func'  => 'getNameAndTime'
)

The second parameter in the $.get jQuery function is the data you are sending to the script.

Upvotes: 1

scrappedcola
scrappedcola

Reputation: 10572

To me it seem of calling the function getnameAndTime somewhere but where

It's not explicitly calling the function 'getNameAndTime' but just a query parameter sent back to the server. 'func' is just the param they are looking for and I suspect the server page that they are hitting ('test.php') will know to call a function of that name.

Upvotes: 0

Related Questions