聚合物核心-ajax在新的聚合物元素中表现得很奇怪

时间:2014-06-29 21:16:53

标签: javascript ajax polymer

我在一个新的聚合物元素中放入了一个core-ajax元素,但是没有响应,我得到了一个访问控制错误。当我在我的index.html中单独使用该元素时,我得到一个常规的响应。知道为什么会这样吗?

聚合物元素:

<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>

的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>

1 个答案:

答案 0 :(得分:3)

在您的自定义元素中,您错过了www子域,它似乎是正常工作所必需的。

相关问题