[英]iron-ajax can not find generateRequest()-Method
I am new to Polymer and try to create an ajax call by iron-ajax. 我是Polymer的新手,尝试通过iron-ajax创建ajax调用。 I run into an error, that
generateRequest()
is undefined. 我遇到一个错误,即
generateRequest()
未定义。
Polymer 1 is in use. 聚合物1在使用中。
I installed iron-ajax with this command: bower install --save PolymerLabs/promise-polyfill#1
我使用以下命令安装了iron-ajax:
bower install --save PolymerLabs/promise-polyfill#1
And as you can see, I load it with <link rel="import" href="../bower_components/promise-polyfill/promise-polyfill-lite.html">
如您所见,我使用
<link rel="import" href="../bower_components/promise-polyfill/promise-polyfill-lite.html">
加载它
I compare it with some examples but can not find the mistake. 我将其与一些示例进行比较,但找不到错误。 Does someone has an idea or solution?
有人有想法或解决方案吗?
this is the code: 这是代码:
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="../bower_components/promise-polyfill/promise-polyfill-lite.html">
<dom-module id="my-view2">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
</style>
<div class="card">
<div class="circle">2</div>
<h1>View Two</h1>
<p>Demo output</p>
</div>
<template is="dom-repeat" items="[[repos]]">
<span>{{items.name}}</span>
</template>
<button on-click="setajax">Click me</button>
<iron-ajax
id="ajax"
url=""
params='{"type":"all"}'
handle-as="json"
on-response="hresponse"
debounce-duration="300" >
</iron-ajax>
</template>
<script>
Polymer({
is: 'my-view2',
setajax: function () {
this.$.ajax.url = "https://api.github.com/users/burczu/repos";
this.$.ajax.params= {"type":"all"};
this.$.ajax.generateRequest();
},
hresponse: function(request) {
console.log(request.detail.response);
console.log(this.$.ajax.lastResponse);
}
});
</script>
</dom-module>
You need to install iron-ajax
: 您需要安装
iron-ajax
:
bower install --save PolymerElements/iron-ajax
Then, you can import using the following code: 然后,您可以使用以下代码导入:
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
Your code will work after you do the above things. 完成上述操作后,您的代码即可使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.