c# - jquery .show shows only at the end -


i want display loading div before ajax command executes webmethod, closing @ end of command. div appears @ end of implementation of ajax command.

the following code block.

$("#dvupprogress1").show(); $.ajax({             type: "post",             url: "producao.aspx/gravarlistasalvar",             data: "",             contenttype: "application/json; charset=utf-8",             datatype: "json",             async: false,             success: function (obj) { }         }); 

in code behind:

[webmethod]     public static string gravarlistasalvar(string idautorizacaoproducaogarantiaqualidade, string idetapa, string idsubetapa, string idusuariologado, string nomecampo, string nomeamigavel, string resposta, string idcampo)     {         ...     } 

you have set post request synchronous, via async: false. browsers don't render things until script finished running - happens after post has finished.

if want progress bar show up, need implement call asynchronously, browser can render the loading div while server processing request. done after call in current routine, move success function have created. javascript should updated so:

$("#dvupprogress1").show(); $.ajax({     type: "post",     url: "producao.aspx/gravarlistasalvar",     data: "",     contenttype: "application/json; charset=utf-8",     datatype: "json",     async: true,     success: function (obj) {         // here rest of code should go      } }); 

you'll notice changed async true, tells browser process call asynchronously, freeing browser render progress bar.

if absolutely must make call synchronously, implement settimeout doing this

$("#dvupprogress1").show(); settimeout(function () {     $.ajax({         type: "post",         url: "producao.aspx/gravarlistasalvar",         data: "",         contenttype: "application/json; charset=utf-8",         datatype: "json",         async: false,         success: function (obj) {             // here rest of code should go          }     }); }, 100); 

.. you're losing benefit of asynchronous processing ajax developed (after all, ajax stands asynchronous js , xml). really, really advise against doing synchronous calls.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -