将signed_request与AJAX调用一起传递到使用CanvasAuthorize装饰的ActionMethod [英] Passing the signed_request along with the AJAX call to an ActionMethod decorated with CanvasAuthorize

查看:101
本文介绍了将signed_request与AJAX调用一起传递到使用CanvasAuthorize装饰的ActionMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是的后续行动AJAX调用在使用CanvasAuthorize进行装饰时不会触发操作方法

所以我发现以下链接,似乎这是一个常见的问题:

So I found the following links and it seems that this is a common problem:

http://facebooksdk.codeplex.com/discussions/251878

http:// facebooksdk .codeplex.com / discussion / 250820

我试图遵循prabir的建议,但我无法让它工作...

I tried to follow the advice by prabir but I couldn't get it to work...

这是我的设置:

我在页面中有以下片段,触发整个帖子到Facebook的按钮是位于:

I have the following snippet in the page where the button that triggers the whole post to facebook is located:

@if (!string.IsNullOrEmpty(Request.Params["signed_request"]))
{
    <input type="hidden" id="signedReq" value="@Request.Params["signed_request"]" />
}

然后我有这个片段(在同一页内的脚本标签内) :

And then I have this snippet (inside a script tag inside the same page):

    var signedRequest = $('#signedReq').val();
    $('.facebookIcon').click(function () {
        var thisItem = $(this).parent().parent();
        var msg = thisItem.find('.compItemDescription').text();
        var title = thisItem.find('.compareItemTitle').text();
        var itemLink = thisItem.find('.compareItemTitle').attr('href');
        var img = thisItem.find('img').first().attr('src');
        postOnFacebook(msg, itemLink, img, title, signedRequest);
    });

最后,在一个外部js文件中,我有以下功能:

And finally, inside an external js file I have the following function:

/*Facebook post item to wall*/
function postOnFacebook(msg, itemLink, pic, itemTitle, signedReq) {
    console.log(signedReq);
    var siteUrl = 'http://www.localhost:2732';
    $.ajax({
        url: '/Facebook/PostItem',
        data: {
            'message': msg,
            'link': siteUrl + itemLink,
            'picture': siteUrl + pic,
            'name' : itemTitle,
            'signed_request': signedReq
        },
        type: 'get',
        success: function(data) {
            if(data.result == "success") {
                alert("item was posted on facebook");
            }
        }
    });
}

但是signedReq始终未定义。而且我不太确定我应该传递数据对象内的'signed_request'字段。任何想法?

But signedReq is always undefined. And I'm not really sure I should be passing the 'signed_request' field inside the data object. Any thoughts?

推荐答案

确保隐藏的输入字段正在填充。

Make sure you hidden input field is being populated.

此外,当您尝试通过JQuery拉取输入字段的ID时,您可能不会引用正确的元素,因为.NET服务器的ID是任何在服务器上运行的。

Also, when you try to pull the ID of the input field via JQuery, you might not be referencing the proper element since .NET butcher's ID's of anything that's run on the server.

当我使用隐藏的输入字段技巧时,我设置jquery值如下:

When I use the hidden input field trick, I set the jquery value like so:

var signedRequest = $('#<%= signedReq。 ClientID%>')。val();

var signedRequest = $('#<%=signedReq.ClientID %>').val();

这样,我得到了.NET给HTML元素的标识符。

This way, I'm getting the identifier that .NET is giving to the HTML element.

希望这有助于。

这篇关于将signed_request与AJAX调用一起传递到使用CanvasAuthorize装饰的ActionMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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