我将核心-ajax元素放置在新的聚合物元素中,但没有响应,但出现访问控制错误。当我在同一URL上的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>

最佳答案

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

关于javascript - polymer 芯-ajax在新的 polymer 元件中表现异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24480362/

10-10 06:12