传递随着AJAX调用的signed_request以饰有CanvasAuthorize的ActionMethod [英] Passing the signed_request along with the AJAX call to an ActionMethod decorated with CanvasAuthorize

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

问题描述

这是一个后续<一个href="http://stackoverflow.com/questions/6057973/ajax-call-does-not-trigger-action-method-when-decorated-with-canvasauthorize">AJAX调用不会触发操作方法当装饰用CanvasAuthorize

所以,我发现下面的链接,似乎这是一个普遍的问题:

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

HTTP://facebooksdk.$c$cplex.com/discussions/251878

HTTP://facebooksdk.$c$cplex.com/discussions/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:

变种signedRequest = $('#&LT;%= 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.

希望有所帮助。

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

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