EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: rezzonico on April 10, 2018, 12:23:34 PM



Title: javascript + ajax
Post by: rezzonico on April 10, 2018, 12:23:34 PM
Hi all,

sorry if this is not a "jeasyui" question but it is part of my "jeasyui program".

I have the following two lines of code:

Code:
$('#id').append('text');
$.ajax({ async: false, ... });

I need to start the ajax function (the second line of the code) in "sync" mode.
The execution time of the ajax function is 10 seconds.

The problem is that the text (the first line of the code) is appended only at the end of the ajax function (after 10 seconds).
Is it possible to append the text immediately ?

Thanks.
Miche


Title: Re: javascript + ajax
Post by: stworthy on April 10, 2018, 04:54:32 PM
Your second line will block the browser to refresh until it finished. The solution to solve this issue is to wait a little time to call your second line.
Code:
$('#id').append('text');
setTimeout(function(){
  $.ajax({ async: false, ... });
},400);


Title: Re: javascript + ajax
Post by: rezzonico on April 11, 2018, 01:35:30 AM
Thanks !

Miche