为什么我的帖子ajax不起作用?

时间:2011-11-25 06:13:59

标签: php jquery ajax facebook facebook-graph-api

我正在做的是facebook请求对话框并从javascript获取用户ID然后发布到php代码将userid插入我的数据库,在我的facebook请求对话框中我可以获取用户ID和请求ID,只有ajax帖子部分不起作用。

我的javascript编码:

function newInvite(){
    FB.ui({ 
    method : 'apprequests',
    title: 'X-MATCH',
     message: 'Come join US now, having fun here',                      
},                      
    function(response){
        var receiverIDs;
        if (response.request)  {
        var receiverIDs = response.to;  // GET USER ID
        alert(receiverIDs);                           
        //I stuck from here
        $.ajax({
            type: "POST",                                       
            url:"<?=$fbconfig['baseUrl']?>/ajax2.php",                                            
            data : {receiverIDs :receiverIDs},
            success: function(msg){
                alert(msg);
            },
            error: function(msg){
            alert(msg);
            }
        });
        }
    }               
);
}

我的php代码(文件名是ajax2.php):

<?php       
include 'config/config.php';
include_once "index.php";  
$Currentdatetime = date("Y-m-d h:i:s" ,strtotime("now"));                       
$senderID = $_POST['receiverIDs'];
$explode = explode(',', $senderID);
for ($i=0; $i<count($explode);$i++){
   mysql_query("INSERT INTO user_invite VALUES('$userid','$explode[$i]','0','50','$Currentdatetime','0')");
}
?>

任何解决方案?感谢

1 个答案:

答案 0 :(得分:3)

您需要在标题中添加jquery:

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'></script>

使用该标记,并阅读Downloading jQuery文章以了解CDN。 Martin是正确的,它是静态内容的最佳方式(例如jquery),但重要的是要了解你在做什么而不仅仅是这样做。

尝试将网址更改为:

$.ajax({
        type: "POST",                                       
        url: "<?=$fbconfig['baseUrl']?>/ajax2.php",                                             
        data : { receiverIDs :receiverIDs },
        success: function(msg){
            alert(msg);
        },
        error: function(msg){
        alert(msg);
        }
    });

你周围不需要两套报价。