[英]How to trigger Ajax ( <iron-ajax > ) call in polymer?
我只想在一些javascript函數中觸發ajax
我的代碼在這里:
<template is="dom-bind" id="app">
<iron-ajax auto url="{{ path('polymer_get_file') }}" handle-as="json" last-response="{{ '{{attachmentResponse}}' }}">
</iron-ajax>
<vaadin-grid items="{{attachmentResponse.results' }}">
<table>
<colgroup>
<col name="index">
<col name="file"/>
<col sortable name="file"/>
<col name="type"/>
</colgroup>
</table>
</vaadin-grid></template><script> function onClick (){
// Here i need to trigger iron-ajax } </script>
您可以調用<iron-ajax>
的generateRequest()
:
<template is="dom-bind" id="app">
<button on-tap="onClick">Send</button>
<iron-ajax id="ajax" ...></iron-ajax>
</template>
<script>
var app = document.getElementById('app');
app.onClick = function() {
this.$.ajax.generateRequest();
};
</script>
HTMLImports.whenReady(() => { const app = document.getElementById('app'); app.onClick = function() { this.response = null; this.$.ajax.generateRequest(); }; app.json = function(obj) { return JSON.stringify(obj, null, 2); }; });
<head> <base href="https://polygit.org/polymer+1.11.3/components/"> <script src="webcomponentsjs/webcomponents-lite.js"></script> <link rel="import" href="polymer/polymer.html"> <link rel="import" href="iron-ajax/iron-ajax.html"> </head> <body> <template is="dom-bind" id="app"> <button on-tap="onClick">Send</button> <iron-ajax id="ajax" url="//httpbin.org/get" last-response="{{response}}"></iron-ajax> <pre>[[json(response)]]</pre> </template> </body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.