2011-06-09 146 views
0

我試圖impliment從最近三個星期的facebook註冊插件,以檢查用戶名avaiablity我使用的jquery和JSON,accourding到這個http://developers.facebook.com/docs/plugins/registration/advanced/指南,以下代碼我能夠發送用戶名到我的服務器是aac#頁面來檢查它是否可用,但如何迴應? 問題是這我不知道如何發送消息從C#頁面調用scritp,以及如何使用閱讀它在這裏。facebook註冊插件異步驗證

<body> 

<div id="fb-root"></div> 

<script src="http://connect.facebook.net/en_US/all.js#appId=134552926621797&xfbml=1"></script> 

<fb:registration redirect-uri="http://dev2.urecommendme.com/test3.aspx" 
    fields='[{"name":"name"}, 
      {"name":"username","description":"Username","type":"text"}]' 
    onvalidate="validate_async"></fb:registration> 

<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script> 
<script> 
    function validate_async(form, cb) { 
     $.getJSON('http://dev2.urecommendme.com/test01.aspx?username=' + form.username + '&callback=?', 
    function (response) { 
     if (response.error) { 
      // Username isn't taken, let the form submit 
      cb(); 
     } 
     alert(cb.toString()); 

    }); 
    } 
</script> 
</body> 

返回的信息應該是這樣的

<script src="http://graph.facebook.com/shahidgfdgd?callback=jsonp1307613510850"> 
jsonp1307613510850({ 
"error": { 
"type": "OAuthException", 
"message": "(#803) Some of the aliases you requested do not exist: shahid" 
} 
}); 
</script> 

這是我的第三個星期implimenting它請指導我,讓我可以完成這個任務,謝謝。

回答

0

FB註冊頁面應該像下面

<body> 

<div id="fb-root"></div> 

<script src="http://connect.facebook.net/en_US/all.js#appId=134552926621785&xfbml=1"></script> 

<fb:registration redirect-uri="http://dev2.urecommendme.com/test3.aspx" 
    fields='[{"name":"name"}, 
      {"name":"username","description":"Username","type":"text"}]' 
    onvalidate="validate_async"></fb:registration> 

<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script> 
<script> 
    function validate_async(form, cb) { 
     $.getJSON('test02.aspx?username=' + form.username, 
    function (response) { 
     if (response.error) { 
      // Username isn't taken, let the form submit 
      cb(); 
     } 
     cb({ username: 'That username is taken' }); 
    }); 
    } 
</script> 

</body> 

注意我怎麼提到服務器文件名(這是不完整的URL,因爲這兩個文件都在同一個根目錄)在validate_async(形式,CB)功能


     $.getJSON('test02.aspx?username=' + form.username, 

Test02.aspx頁面應該像下面



注意沒有HT ml,body或head標籤中test02.aspx (Test02.aspx.cs)應該看起來像


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Newtonsoft.Json; 
using System.Text; 

public partial class test02 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e1) 
    { 
     StringBuilder JSON = new StringBuilder(); 

     //validate from your database and execute one of the following two lines. 

     JSON.Append("{\"error\":\"Exist\"}"); // username is taken 

    // JSON.Append("{\"anything\":\"Not Exist\"}"); 


     Response.Write(JSON.ToString()); 

     Response.End(); 

    } 
}