我想在发送的第一个请求完成之前停止 iron-ajax 发送的第二个请求



>我有一个 api,大约需要 4 分钟才能完成我的聚合物应用程序。当我在正好 2 分钟发送请求时,即使在超时和去抖动持续时间设置为 10 分钟后,也会发送另一个请求。我想停止发送的第二个请求或等待第一个请求完成。有些人建议我使用 fetch 而不是 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等。

最新更新