2011-11-25 82 views
1

我在做什么是Facebook请求对话框,并从JavaScript获取用户ID,然后发布到php代码插入用户ID在我的数据库中,在我的Facebook请求对话框部分我可以获取用户ID和请求ID,只有ajax邮件部分不管用。为什么我的帖子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')"); 
} 
?> 

任何解决方案?感谢

+0

你是否试图在萤火虫控制台中看到这个? – Arfeen

+0

在我的firebug中显示“$未定义” – Oscar

+0

@user您是否将jQuery添加到页面中? –

回答

3

您需要添加的jQuery到页眉:

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

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

尝试改变网址:

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

你不需要2台周围的引号的。

+0

感谢您的回复,我已经编辑我的代码,看看我改变了什么,但仍然是它不工作 – Oscar

+0

谢谢安德鲁杰克曼,我明白你的意思,我已经添加在我的标题jQuery,现在它的工作,非常感谢您的帮助:D – Oscar

+0

@Andrew他为什么要“记住”? '但要确保你记得'。嗯,请再次编辑您的帖子,以便我可以删除这个downvote, –