2011-06-09 114 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(); 

    } 
}