为什么我得到generateRequest Polymer iron-ajax的"不是函数"错误

Jer*_*rry 0 javascript ajax polymer

未捕获的TypeError:this.$.ajax.generateRequest不是函数Polymer.setajax @ assets-ajax.html:23 handler @ polymer.html:390 assets -ajax.html

<dom-module id="assets-pull">
<style>
</style>
<template>

    <button on-click="setajax">Click me</button>

    <iron-ajax
            id="ajax"
            url=""
            handle-as="json"
            on-response="hresponse"
            debounce-duration="300">
    </iron-ajax>

</template>
<script>
    Polymer({
        is: "assets-pull",
        setajax: function () {
            this.$.ajax.url = "http://mytesturl.com/assets_all";
            this.$.ajax.params = {"userId":"1"};
            this.$.ajax.generateRequest();
        },
        hresponse: function(request) {
            console.log(request.detail.response);
            console.log(this.$.ajax.lastResponse);
        }
    });
</script>
Run Code Online (Sandbox Code Playgroud)

Dev*_*Dev 7

你的代码适合我.确保安装并导入iron-ajax元素.

例:

<link rel="import" href="../components/iron-ajax/iron-ajax.html">
<dom-module id="assets-pull">
  ...
</dom-module>
Run Code Online (Sandbox Code Playgroud)