簡體   English   中英

聚合物芯-ajax

[英]Core-ajax in Polymer

我只是將Web組件與Polymer一起使用的初學者。 我使用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" ,不會發生此錯誤。 我怎么了? 對不起,如果我的英語不好。 非常感謝。

您的嘗試違反了同源政策 您所需的服務器未設置Access-Control-Allow-Origin標頭,這將阻止瀏覽器執行跨域XMLHttpRequest

旁注:設置responseon-×××-response都是多余的。 前者用於將響應綁定到變量,后者用於設置響應的處理程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM