2011-11-25 51 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, –