If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

AJAX Aborting

Currently, I have a class set up in Ajax that calls certain pages.
I have a page that has a 5-second sleep to it (because I was checking something); however, the issue is if that page is still getting called I want to cancel and stop the 5-second page call (or any page for that matter) and start the other ajax call.

Well, path is not defined. And there seems to be other confused or maybe just confusing code. For example:

Code:

var instance = $(this);

Now, instance doesn't appear to get used elsewhere anyway, but this in this case appears to be the prototypical function, so $'ing it would be meaningless. Another thing is, if you're using jQuery (looks like it), it should be 'click' not 'onclick'. There are number of other things like this, or that just seem over thought and more complicated than needed.

Since it looks like you're using jQuery. Why not use its tried and true methods? Something like (in simplest terms):

which is, as I'm pretty sure you know, both a 'setter' and a 'getter', so pretty powerful, considering it's the current page location/address. Now the way you have it there is qualified, but perhaps not enough in all circumstances. And even if it is in that case, once you start using it as a parameter/variable, sooner or later a situation may easily arise where it's misinterpreted for its proprietary meaning. Many people us "loc" or really any other non-proprietary word for that very reason.

Other thoughts I had on your code that I hope may be helpful - You seem to be wanting to graft generic prototypical javascript constructs on or around jQuery. And that can be done. What I think many who do that don't realize is that jQuery is already prototypical in its own way, so often these efforts are redundant. As an example, I see you listing defaults for the call you eventually make via $.ajax. These can be established with:

Whatever you include in the object for that function will become the default(s) for any subsequent AJAX call executed via jQuery regardless of whether or not it's via $.ajax or any of the shorthand/specific jQuery AJAX methods, and can/will be overridden by specific settings for any subsequent call. So all that was already available. There are many other situations like this in jQuery, and although it's not required one use them, generally once you've loaded jQuery, using what it gives you will be more efficient and simpler to deal with in the long run.

These are just general suggestions, and while I'm at it I should try to explain that using a classic javascript prototypical function is largely ubiquitous with jQuery. The usually more efficient analogous (yet decidedly different) method is to extend the jQuery object itself with a new tailor made function, applicable to any selector (one at a time, a combined selector, or various ways, like any native jQuery function) and capable (depending upon how you define it) of accepting additional parameters and/or an object of parameters. See (for more info):

Thanks for that information. I didn't see that I used location and switched it to loc.
I'm actually trying to not use JQuery in some instances and slowly start using javascript. (At least in some instances).
I haven't updated the page to display any of the changes. EG I dropped using $.ajax and created a personal HTTP request.