polymer - 即使在发送的第一个请求完成之前,我也想停止 Iron-ajax 发送的第二个请求
问题描述
我有一个 api 需要 4 分钟(大约)才能在我的聚合物应用程序中完成。当我在准确的 2 分钟发送请求时,即使在超时并且去抖动持续时间设置为 10 分钟后,也会发送另一个请求。我想停止发送第二个请求或等待第一个请求完成。有些人建议我使用 fetch 而不是 Iron-ajax。我需要修复 iron-ajax 本身。我可以为此提供解决方案吗?
代码在这里
<iron-ajax id="request"
url={{request}}
verbose
handle-as="json"
method="{{method}}"
body="{{body}}"
params="{{requestParams}}"
on-error="onError"
loading="{{loading}}"
timeout=600000
content-type="application/json"
debounce-duration=600000
last-error="{{lastError}}"
last-response="{{lastResponse}}">
我希望这会得到解决。提前致谢
解决方案
您可以设置一个布尔变量,以便能够调用this.$.request.generateRequest()
类似:
static get properties() {return {
_isRequest: {
type: Boolean,
value: true}}}
static get observers(){ return ['_checkLastResponse(lastResponse)'] }
__checkLastResponse(r) {
// we have received a response from iron-ajax so allow for next call
if (r) this._isRequest = true;}
// As you provided above code, you call ajax manually.
_ajax_call() {
if (this._isRequest) {
this.$.request.generateRequest();
this._isRequest = false; }
}
static get template() { return `
<paper-button disabled="[[!_isReruest]]" on-tap="ajax_call">AJAX CALL</paper-button>
.......
`;}
因此,您可以删除不必要的属性等debounce-duration=600000
。
推荐阅读
- javascript - 处理数据并记录谁来自请求
- reactjs - 如何使用下划线在 redux 中返回新状态?
- vue.js - NuxtServerInit 在 Vuex 模块模式下不起作用 - Nuxt.js
- sql - 如何在 postgres 中获取 UPSERT 操作的 INSERTED 和 UPDATED 行
- regex - 表达式解析器正则表达式
- excel - 循环数据验证列表
- jenkins - Map 根据键名取值时返回 null
- apache-camel - https4 apache camel 给出的主机名与对端提供的证书主题不匹配
- css - 导入 typekit url 时使用字体显示
- node.js - 如何为我的 NodeJS 应用程序解决这个 DB2 驱动程序错误?