简体   繁体   中英

Force synchronous XMLHttpRequest / Ajax without warning

Ok so obviously synchronous has been deprecated because it is bad for the user experience.

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/

And we all know that. But I still want to use it for something completely different than the user experience, on the development side. I understand they don't want it used, but why remove the feature? These kind of things should be accesible via the "non-default" configuration via the options symbolizer. IMO it will be reversed one day.

Anyway, the question is: What kind of hack can I use to emulate synchronous Ajax or XMLHttpRequest, without receiving the warning message? My assumption is eventually it won't work in the browsers once they fully deprecate it.

Edit : This solution doesn't work. I'll leave it here to discourage trying a similar method. If someone can actually find a working solution, I'll remove this answer.

If you really want to fake a synchronous ajax request, you can use jQuery's .delay() function, and just keep checking if an asynchronous request is complete.

function fakeSynchronous(ajaxSettings) {
  var promise = $.ajax(ajaxSettings);
  while (promise.state() === "pending") {
    $("html").delay(1000);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM