聚合物中的核心-ajax

时间:2015-03-18 07:56:12

标签: ajax polymer web-component

我刚开始使用带有Polymer的Web Components。我使用core-ajax但是出了点问题。请帮我修复我所犯的错误。          

<polymer-element name="x-ajax">
    <template>
        <core-ajax
            id='ajax'
            auto
            handleAs='json'
            url="http://api.istockvina.com/watchlist"
            response="{{response}}"
            on-core-response="{{handleResponse}}"
            on-core-error="{{handleError}}"
            >
        </core-ajax>
        {{data}}
    </template>
    <script>
        Polymer({
            data: [],
            ready: function(){
                alert('ready');
            },
            handleError: function(){
                alert(JSON.stringify(this.$.ajax.error));
            },
            handleResponse: function(){
                alert('done');
                this.data = JSON.stringify(this.$.ajax.response);
            }
        });
    </script>
</polymer>

错误为{"statusCode":0,"response":""}。当我改变链接 url="http://www.filltext.com"错误不会发生。我错了什么?对不起,如果我的英语太差了。非常感谢。

1 个答案:

答案 0 :(得分:1)

您的尝试违反了Same-origin policy。您所需的服务器未设置Access-Control-Allow-Origin标头,这会阻止浏览器执行跨域XMLHttpRequest

旁注:同时设置responseon-×××-response是多余的。前者用于绑定对变量的响应,后者用于设置响应的处理程序。

相关问题