如何使用原型js库中止/取消请求?

Mr.*_*ves 15 javascript ajax prototypejs

使用此代码:

var pendingRequest =  new Ajax.Request(myUrl, {
               method: 'post',
               postBody: soapMsg,
               contentType: "text/xml",
               onSuccess: function(transport) {
                    doSomething(transport);
               },
               onFailure: function(t) {
                    OnAjaxFailure(t);
               },
               onException: function(req,exception) { 
                    OnAjaxException(req, exception);          
               } 

            }); 
Run Code Online (Sandbox Code Playgroud)

如何取消请求并丢弃数据,或者如果失败,我怎么能在我的onSuccess方法中识别请求(使用名称/ guid /等),以便我可以告诉哪个请求正在完成?

我正在考虑做一个array.push(pendingRequest)来跟踪待处理的请求

我想允许用户中断他们的请求,更改输入值并重新提交.

有时原始请求在新请求之后结束,我用"旧"数据替换"正确"数据.(搜索结果在第一个查询中返回50,000条记录,在第二个查询中返回5条记录,例如)

谢谢,

Ven*_*ero 20

您可以使用XHR的中止.

XHR对象存储在pendingRequest.transport中,因此使用

pendingRequest.transport.abort()
Run Code Online (Sandbox Code Playgroud)

将取消该请求.