2011-02-14 67 views
1
$.ajax({ 
    type: "POST", 
    url: "some.php", 
    data: "name=John&location=Boston", 
    success: function(msg){ 
    alert("Data Saved: " + msg); 
    } 
}); 

下面是使用jQuery阿贾克斯变量发送到PHP页面进行处理,完成后,你在哪里得到返回的HTML或JSON等典型的例子...你可以执行回调函数而不是整个php文件吗?

我在WordPress允许使用的东西ajax被发送到所有处理的回调函数,而不是整个php页面。

基本上我想在ajax.php中拥有所有的回调函数,所以它更有条理。

感谢

+1

和..你有什么问题? – 2011-02-14 01:35:22

回答

1

是的,只需提交一个参数,如以下到PHP文件:

data: "name=John&location=Boston&cmd=something", 

在PHP文件的顶部,这样做:

<? 
if (isset($_GET['cmd']) && $_GET['cmd']=='something') 
{ 
    yourCallbackFunction(); 
    die; 
} 
//Rest of processing goes here 
?> 
+1

请务必在发布时使用`$ _POST`; – 2011-02-14 01:55:40

相关问题