Dror
Dror

Reputation: 21

Jquery Ajax call not allowing other links to act normally

I have a page with many "normal" links (<a href=XXX>) , part of this page is fetching data via jQuery Ajax method (this call might take around 20-30 seconds ...).

I've found out that if I press one of the links while the Ajax call is still running, I cannot redirect normally to the link's address and I have to wait till the Ajax call is finished (even though it's supposed to be asynchronous... isn't it?)

I guess I have to abort the Ajax call if any link is being pressed before it is finished - anyone can enlighten me how to do so?

Cheers,

Upvotes: 2

Views: 200

Answers (1)

Reza Hashemi
Reza Hashemi

Reputation: 1837

If the links do not work, your ajax call should be synchronous. Synchronous (blocking) requests (async:false) lock your browser and prevent it from doing any action.

Check your code to see if you have passed a false async parameter to .ajax function. If you return the result of the .ajax call to a variable, you should have used a blocking request.

jQuery.ajax Example: Loads data synchronously. Blocks the browser while the requests is active. It is better to block user interaction by other means when synchronization is necessary.

var html = $.ajax({

  url: "some.php",

  async: false

 }).responseText;

Upvotes: 2

Related Questions