Javascript 聚合物芯ajax在新的聚合物元素中表现怪异
我将一个核心ajax元素放在一个新的聚合元素中,但没有得到响应,而是得到了一个访问控制错误。当我在同一url上单独使用index.html中的元素时,我会得到一个常规响应。知道为什么会这样吗 聚合物元素:Javascript 聚合物芯ajax在新的聚合物元素中表现怪异,javascript,ajax,polymer,Javascript,Ajax,Polymer,我将一个核心ajax元素放在一个新的聚合元素中,但没有得到响应,而是得到了一个访问控制错误。当我在同一url上单独使用index.html中的元素时,我会得到一个常规响应。知道为什么会这样吗 聚合物元素: <link rel="import" href="components/polymer/polymer.html"> <link rel="import" href="components/core-ajax/core-ajax.html"> <polymer-
<link rel="import" href="components/polymer/polymer.html">
<link rel="import" href="components/core-ajax/core-ajax.html">
<polymer-element name="reddit-service" attributes="posts subreddit">
<template>
<style>
:host {
display: block;
}
</style>
<core-ajax
auto
url="http://reddit.com/.json"
on-core-response="{{ajaxResponse}}"
handleAs="json"></core-ajax>
</template>
<script>
Polymer('reddit-service', {
created: function() {
this.posts = [];
},
ajaxResponse: function(event, response) {
console.log(event);
}
});
</script>
</polymer-element>
:主持人{
显示:块;
}
聚合物(“reddit-service”{
已创建:函数(){
this.posts=[];
},
ajaxResponse:函数(事件、响应){
console.log(事件);
}
});
index.html:
<!DOCTYPE html>
<html>
<head>
<!-- META AND STUFF -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Polymer Reddit App</title>
<!-- POLYMER -->
<script src="components/platform/platform.js"></script>
<link rel="import" href="components/core-ajax/core-ajax.html">
<link rel="import" href="components/core-header-panel/core-header-panel.html">
<link rel="import" href="components/core-toolbar/core-toolbar.html">
<link rel="import" href="reddit-list.html">
</head>
<body unresolved>
<core-toolbar>Reddit with Polymer</core-toolbar>
<core-ajax
auto
url="http://www.reddit.com/.json"
handleAs="json"></core-ajax>
<script>
function handle(event, response) {
console.log(event);
}
document.addEventListener('core-response', handle, false);
</script>
</body>
</html>
聚合Reddit应用程序
聚合物红
函数句柄(事件、响应){
console.log(事件);
}
文档。addEventListener('core-response',handle,false);
在自定义元素中,您缺少www
子域,它似乎是它正常工作所必需的