Avatar of ldbkutty
ldbkutty
Flag for India asked on

jQuery: "async: false" with "beforeSend"

Hi All,

The following code works good in Firefox, and displays the "Loading" image till there's a response. But the same does not show the "Loading" image in other browsers (IE, Safari).

I found somewhere that having both

async: false

and

beforeSend

doesn't go hand-in-hand. According to http://api.jquery.com/jQuery.ajax/#options : Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

Is there any workaround? Please advise.
var resp = $.ajax({
    url: myUrl,
    async: false,
    beforeSend: function () {
        jQuery('loading').show();
    },
    success: function(data, result) {
        jQuery('loading').hide();
    }
}).responseText;

Open in new window

jQueryJavaScriptAJAX

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zvonko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ldbkutty

ASKER
Zvonko, Simple & powerful, as always :)

Thanks!
Michel Plungjan

Why not


jQuery('loading').show();
setTimeout(function(){
  var resp = $.ajax({
    url: myUrl,
    async: false,
    success: function(data, result) {
        jQuery('loading').hide();
    }
  }).responseText;
},10);

Open in new window

Zvonko

Good question, I dono know. Perhaps to hide it double :)
Your help has saved me hundreds of hours of internet surfing.
fblack61