我试图在过去三周内诋毁facebook注册,检查用户名avaiablity我正在使用jquery和JSON,参与此http://developers.facebook.com/docs/plugins/registration/advanced/指南,使用以下代码我可以将用户名发送给我服务器是aac #page来检查它是否可用,但如何告知? 问题是我不知道如何从c#page发送消息到调用scritp,以及如何使用在这里读取它。
<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>
这是我的第三个星期,请指导我,所以我可以完成这项任务,谢谢。
答案 0 :(得分: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>
请注意我在validate_async(form,cb)函数中提到的服务器文件名(它没有完整的URL,因为两个文件都在同一个根目录下)
$.getJSON('test02.aspx?username=' + form.username,
Test02.aspx页面应如下所示
注意test02.aspx中没有html,body或head标签 (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();
}
}