开发者

Can you execute a callback function instead of a whole php file?

开发者 https://www.devze.com 2023-02-10 19:44 出处:网络
$.ajax({ type: \"POST\", url: \"some.php\", data: \"name=John&location=Boston\", success: function(msg){
$.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
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消