Facebook的注册插件异步验证 [英] facebook registration plug-in Async Validation

查看:128
本文介绍了Facebook的注册插件异步验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想impliment Facebook的注册,从过去的三个星期pluging,检查我使用jQuery和JSON的用户名avaiablity,accourding本的 http://developers.facebook.com/docs/plugins/registration/advanced/ 指导,用下面的code,我能够发送用户名我服务器是AAC#页,以检查它要么是可用的,但如何分辨回来?
问题是这样的,我不知道如何从C#页发送消息给调用scritp,以及如何使用这里阅读。

I am trying to impliment facebook registration pluging from last three weeks, to check the username avaiablity I am using jquery and JSON, accourding to this http://developers.facebook.com/docs/plugins/registration/advanced/ guide, with the following code I am able to send username to my server that is a a c# page to check either it is available or not, but how to tell back? Problem is this I don’t know how to send message from c# page to the calling scritp, and how to use read it here.

<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>

返回消息应该是这样的。

Returning message should be something like this

<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它请指导我,让我可以完成这个任务,谢谢。

This is my third week to implimenting it please guide me so I can complete this task, thanks.

推荐答案

FB注册页面看起来应该如下:

FB registration page should look like as follows

<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)功能

Note how I mentioned server file name (it is without full URL, as both files were on same root dir) in validate_async(form, cb) function


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

Test02.aspx页应该看起来像如下:

Test02.aspx page should look like as follows



请注意在test02.aspx没有HTML,躯干或头部标记
(Test02.aspx.cs)应该像

Note no html, body or head tags in test02.aspx (Test02.aspx.cs) should look like


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(); 

    }
}

这篇关于Facebook的注册插件异步验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆