【发布时间】:2018-02-24 03:25:20
【问题描述】:
有没有人遇到过 Iron-ajax 的响应事件为单个请求触发两次?我已经仔细检查过,实际上我正在提交一个请求。这是我的 Iron-ajax 实现(只是一个包装 Iron-ajax 的元素):
<dom-module id="my-ajax">
<template>
<iron-ajax id="ajax" auto="{{auto}}" url="{{url}}" method="{{method}}" headers="{{headers}}" body="{{body}}" handle-as="json" content-type="application/json" on-response="responseHandler" on-error="errorHandler" with-credentials></iron-ajax>
</template>
</dom-module>
// Register the polymer element
Polymer({
is: 'my-ajax',
properties: {
actionDesc: {type: String, value: ""},
auto: {type: Boolean, value: false},
body: {type: String, value: null},
headers: {type: Object, value: null},
isBusy: {
// One-way binding setup (i.e. child to host only)
type: Boolean,
value: false,
readOnly: true,
notify: true
},
method: {type: String, value: null},
user: {type: Object, value: null},
url: {type: String, value: null}
},
generateRequest: function() {
if (!this.isBusy) {
// Execute request as it isn't currently busy processing a previous request
this.isBusy = true;
this.$.ajax.generateRequest();
} else {
// TODO: Queue up this request
}
},
responseHandler: function(e, detail) {
console.log(this.id + " responseHandler fired!\n");
this.isBusy = false;
this.fire("handle-response", detail.xhr.response);
}
});
【问题讨论】:
标签: polymer polymer-1.0