0

我有一个获取我的 facebook 'uid' 和 'accesstoken' 的 javascript,有没有一种方法可以在触发时将这些值传递给我的 Ajax ActionLink,以便我可以重定向到接受 2 参数的我的 'Publish' 控制器。谢谢。

<script type="text/javascript">

    var uid = 0;
    var accesstoken = '';

    function grantPermission() {
        window.FB.login(function (response) {
            if (response.authResponse) {
                uid = response.authResponse.userID;
                accesstoken = response.authResponse.accessToken;
                var postData = { facebookUID: uid, facebookAccessTok: accesstoken };
                $.ajax({
                    url: '@Url.Action("Index","Tab")',
                    type: 'POST',
                    data: postData,
                    dataType: 'json',
                    success: function (response) {
                        // process the results from the controller action
                        // window.location.href = response.Url;
                    }
                });
            } else {
                console.log('User cancelled login or did not fully authorize.');
                alert('User cancelled login');
            }
        }, { scope: 'publish_stream' });
    };
</script>

      <html>
    <head>
        <title>Facebook Login Authentication Example</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>

    </head>
    <body>

        <h1>Facebook Login Authentication</h1>
        <br/>

        @Ajax.ActionLink("Proceed", "Publish", "Tab",
        new { id = "auth-loginlink" },
        new AjaxOptions{UpdateTargetId = "DynamicContainer",
                        InsertionMode=InsertionMode.Replace,
                        HttpMethod="POST",
                        OnSuccess = "grantPermission()" 
        })

        <br/><br/>

        <div id="DynamicContainer" style="border: 1px solid #C0C0C0; padding: 1px; width: 500px; height: 400px"></div>

    </body>
</html>

发布控制器:

public PartialViewResult Publish( string accTok, string fullImgPath)
    {
        if (accTok != null && fullImgPath != null)
        {
             UploadPhoto(accTok, fullImgPath);
            // PostToWall(accTok, fullPath);
             return PartialView("BlurredPhoto");
        }
        return PartialView("Blank");
    }
4

1 回答 1

0

This should work, if the IndexAction on the TabController accepts two parameters and they are actually named facebookUID and facebookAccessTok.

于 2012-08-21T06:09:46.387 回答