聚合物核 - ajax交叉域问题 [英] Polymer core-ajax cross domain issue

查看:265
本文介绍了聚合物核 - ajax交叉域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Polymer和 core-ajax 组件。我一直回到在请求的资源上没有Access-Control-Allow-Origin头。组件的代码位于

下面

 < core-ajax id =ajax
auto
url =http://api.meetup.com/2/event_comments/?key=MyKey&event_id=191593992&callback=?
on-core-response ={{commentsLoaded}}
method ='GET'
contentType ='text / javascript'
handleAs =json>
< / core-ajax>

如果我使用jQuery和以下代码片段,它工作

  $ .getJSON('http://api.meetup.com/2/event_comments/?key=MyKeyc&event_id=191593992&callback=?')$ b $所以我想我的问题是什么巫术魔法是jQuery使用聚合物不是,我怎么解决它?我已经检查控制台,一切看起来是一样的(头,参数等)。

解决方案

正如恰当的名字Jason P指出您可以在这里使用polymer-jsonp。

 < polymer-jsonp 
auto
url =http://api.meetup.com/2/event_comments/?key=MyKeyc&event_id=191593992&callback=
on-polymer-response ={{commentsLoaded}}>
< / polymer-jsonp>


I am trying to do a cross domain call using Polymer and the core-ajax component. I keep getting back No 'Access-Control-Allow-Origin' header is present on the requested resource. My code for the component is below

    <core-ajax id="ajax"
        auto
        url="http://api.meetup.com/2/event_comments/?key=MyKey&event_id=191593992&callback=?"
        on-core-response="{{commentsLoaded}}"
        method='GET'
        contentType='text/javascript'
        handleAs="json">
    </core-ajax>

If I use jQuery and the following snippet, it works

$.getJSON('http://api.meetup.com/2/event_comments/?key=MyKeyc&event_id=191593992&callback=?')

So I guess my question is what voodoo magic is jQuery using that Polymer is not and how do I get around it? I have checked the console and everything looks identical (headers, params etc).

解决方案

As the aptly named Jason P points out in the comments above, you can use polymer-jsonp here.

<polymer-jsonp 
    auto 
    url="http://api.meetup.com/2/event_comments/?key=MyKeyc&event_id=191593992&callback=" 
    on-polymer-response="{{commentsLoaded}}">
</polymer-jsonp>

这篇关于聚合物核 - ajax交叉域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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