[英]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
。
旁注:設置response
和on-×××-response
都是多余的。 前者用於將響應綁定到變量,后者用於設置響應的處理程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.