[英]I want to stop the second request that is sent by the iron-ajax even before the first request sent is completed
I have an api that takes 4 mins(approx.) to get completed in my polymer application. 我有一个需要4分钟(大约)的api在聚合物应用程序中完成。 When I send the request at exact 2mins another request gets sent even after timeout and debounce-duration is set to 10 mins.
当我在精确的2分钟发送请求时,即使超时后也发送了另一个请求,并且将反跳时间设置为10分钟。 I want to stop that second request sent or wait for the first request to get completed.
我想停止发送第二个请求,或者等待第一个请求完成。 Some suggested me to use fetch instead of iron-ajax.
有人建议我使用fetch代替iron-ajax。 I need a fix in iron-ajax itself.
我需要修复铁ajax本身。 Can I have a solution for this.
我可以为此提供解决方案吗?
code goes here 代码在这里
<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}}">
I hope this will get resolved. 我希望这会解决。 Thanks in advance
提前致谢
You can set a Boolean variable in order to able call this.$.request.generateRequest()
something like: 您可以设置一个布尔变量,以便能够调用
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>
.......
`;}
So, you may remove the unnecessary properties something like debounce-duration=600000
etc. 因此,您可以删除不必要的属性,例如
debounce-duration=600000
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.