EXTJS 4:选择性Ajax请求中止

时间:2022-10-14 20:51:46

In my application I have many ajax request that executes every now and then. I have one that executes with a settimeout another is with a user interaction. My problem is the user interaction part.

在我的应用程序中,我有许多不时执行的ajax请求。我有一个用settimeout执行另一个用户交互。我的问题是用户交互部分。

The scenario is when the user sets the parameter and clicks the button it executes a ajax request. If he makes a mistake with its parameter the user will adjust something and then execute again the ajax request, with the previous request still on going.

该场景是当用户设置参数并单击它执行ajax请求的按钮时。如果他的参数出错,用户将调整一些内容,然后再次执行ajax请求,之前的请求仍在进行中。

I want to abort the previous request without using the abortall() because like I said before there are other request that should not be interrupted. So its like selecting a request to abort. How do I do that? Please Help.

我想在不使用abortall()的情况下中止上一个请求,因为就像我之前所说的那样,有其他请求不应该被中断。所以就像选择中止请求一样。我怎么做?请帮忙。

1 个解决方案

#1


3  

There is a property on Ext.Ajax autoAbort : Boolean

Ext.Ajax autoAbort:Boolean上有一个属性

Whether a new request should abort any pending requests.

新请求是否应中止任何挂起的请求。

Defaults to: false

默认为:false

Available since: 1.1.0

可用时间:1.1.0

set this prop to true on your Ajax sent by user, so it will not interfere with setInterval ajax's. Also, make sure that you have a client side and a server side validation, so bad params will be avoided. Solving bad params on client side is much quicker, cheaper and user friendly thing to do than let user submit falsy data!

在用户发送的Ajax上将此prop设置为true,因此它不会干扰setInterval ajax。此外,请确保您具有客户端和服务器端验证,因此将避免错误的参数。在客户端解决错误的params要比让用户提交虚假数据更快,更便宜和用户友好的事情!

Ext.Ajax.request({
    url: '/echo/json/',
    params: {
        id: 1
    },
    autoAbort : true, 
    success: function(response){        
          //do something
    },
    failure:function(response){
         //do something
    }
});

Here is example on fiddle!

#1


3  

There is a property on Ext.Ajax autoAbort : Boolean

Ext.Ajax autoAbort:Boolean上有一个属性

Whether a new request should abort any pending requests.

新请求是否应中止任何挂起的请求。

Defaults to: false

默认为:false

Available since: 1.1.0

可用时间:1.1.0

set this prop to true on your Ajax sent by user, so it will not interfere with setInterval ajax's. Also, make sure that you have a client side and a server side validation, so bad params will be avoided. Solving bad params on client side is much quicker, cheaper and user friendly thing to do than let user submit falsy data!

在用户发送的Ajax上将此prop设置为true,因此它不会干扰setInterval ajax。此外,请确保您具有客户端和服务器端验证,因此将避免错误的参数。在客户端解决错误的params要比让用户提交虚假数据更快,更便宜和用户友好的事情!

Ext.Ajax.request({
    url: '/echo/json/',
    params: {
        id: 1
    },
    autoAbort : true, 
    success: function(response){        
          //do something
    },
    failure:function(response){
         //do something
    }
});

Here is example on fiddle!