[Javascript] Prevent Prototype Ajax from firing twice
Scott Reynen
scott at randomchaos.com
Wed Feb 20 11:25:50 CST 2008
On Feb 20, 2008, at 3:45 AM, Michael Borchers wrote:
> Is there a way to prevent Prototype doing one AJAX call several
> times? F.e. writing it into a var or getting a global AJAX status
> and to check if it already exists?
I just recently did this in JQuery and was surprised it wasn't already
built in (that I could find, anyway). What I did was just create a
global urlRequested array, and then make requests something like this:
if ( ! urlRequested[ url ] )
{
urlRequested[ url ] = true;
// request url
}
If you're only seeking to prevent duplicate requests while the first
request is pending, you can set urlRequested[ url ] = false in your
response handler. Otherwise the requests will only go once ever.
This gets more complicated if your requests are distinguished by more
than just URL, but the same general technique should work.
Peace,
Scott
More information about the Javascript
mailing list