Uncaught TypeError:this。$。ajax.generateRequest不是函数Polymer.setajax @ assets-ajax.html:23 handler @ polymer.html:390 资产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>
答案 0 :(得分:7)
您的代码适合我。确保安装并导入iron-ajax元素。
示例:
<link rel="import" href="../components/iron-ajax/iron-ajax.html">
<dom-module id="assets-pull">
...
</dom-module>