Can you execute a callback function instead of a whole php file?
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
Here is a typical example using jquery ajax to send variables to a php page开发者_高级运维 for processing, where upon completion you get the returned html or json etc...
I used something in wordpress that allows for the ajax to be sent to a callback function for all the processing instead of a whole php page.
Basically I want to have all my callback functions in ajax.php and so it's more organized.
Thanks
Yes, simply submit an argument like the following to your PHP file:
data: "name=John&location=Boston&cmd=something",
At the top of the PHP file, do this:
<?
if (isset($_GET['cmd']) && $_GET['cmd']=='something')
{
yourCallbackFunction();
die;
}
//Rest of processing goes here
?>
精彩评论