最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to you abortcancel a request using the prototype js library? - Stack Overflow

programmeradmin3浏览0评论

Using this code:

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);          
               } 

            }); 

How can I cancel the request and discard the data, or failing that, how could I identify the request (using a name/guid/whatever) inside my onSuccess method so that I can tell which request is completing?

I was thinking of doing an array.push(pendingRequest) to keep track of pending requests

I want to allow the user to interrupt their request, change the input values and resubmit.

Sometimes the original request ends after the new request and I'm replacing the "correct" data with the "old" data. (search results return 50,000 records on the first query and 5 in the second, for example)

Thanks,

Using this code:

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);          
               } 

            }); 

How can I cancel the request and discard the data, or failing that, how could I identify the request (using a name/guid/whatever) inside my onSuccess method so that I can tell which request is completing?

I was thinking of doing an array.push(pendingRequest) to keep track of pending requests

I want to allow the user to interrupt their request, change the input values and resubmit.

Sometimes the original request ends after the new request and I'm replacing the "correct" data with the "old" data. (search results return 50,000 records on the first query and 5 in the second, for example)

Thanks,

Share Improve this question asked Jul 1, 2010 at 21:10 Mr. GravesMr. Graves 4524 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 22

You can use XHR's abort.

The XHR-object is stored in pendingRequest.transport, so using

pendingRequest.transport.abort()

would cancel the request.

发布评论

评论列表(0)

  1. 暂无评论