Jerry
Jerry

Reputation: 961

Why am I getting "is not a function" error for generateRequest Polymer iron-ajax

Uncaught TypeError: this.$.ajax.generateRequest is not a function 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>

Upvotes: 0

Views: 5606

Answers (1)

Dev
Dev

Reputation: 367

Your code works for me. Make sure iron-ajax element is installed and imported.

Example:

<link rel="import" href="../components/iron-ajax/iron-ajax.html">
<dom-module id="assets-pull">
  ...
</dom-module>

Upvotes: 7

Related Questions