javascript - Showing message before page refresh using jQuery -


i want display ajax result message before page refresh, wrong. code this:

$.ajax({     cache: false,     type: "post",     url: "@(url.routeurl("dummyrequest"))",     success: function (data) {         if (data.success) {             $('#dummy-notification').text(data.result).fadein("slow").delay(3000).fadeout("slow");             setinterval(function () {                 location.reload();             }, 5000);         }         else {             $('#dummy-notification').text(data.result).fadein("slow").delay(3000).fadeout("slow");             /*setinterval(function () {                 location.reload();             }, 5000);*/         }     },     error: function (xhr, ajaxoptions, thrownerror) {         $('#dummy-notification').text("something went wrong.").fadein("slow").delay(3000).fadeout("slow");     } }); 

my code working fine on else situation. when tried, message appears, after 5 secs page reloads itself. when if situation on, page reloads itself, message doesn't show.

how can solve problem?

its depends on response time of server.. if response server late not working correctly.. have wait ajax response have display popup , redirect. use ajax option async: false in ajax request. mentioned below

$.ajax({     cache: false,     async: false,     type: "post",     url: "@(url.routeurl("dummyrequest"))",     success: function (data) {         if (data.success) {             $('#dummy-notification').text(data.result).fadein("slow").delay(3000).fadeout("slow");             setinterval(function () {                 location.reload();             }, 5000);         }         else {             $('#dummy-notification').text(data.result).fadein("slow").delay(3000).fadeout("slow");             /*setinterval(function () {                 location.reload();             }, 5000);*/         }     },     error: function (xhr, ajaxoptions, thrownerror) {         $('#dummy-notification').text("something went wrong.").fadein("slow").delay(3000).fadeout("slow");     } }); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -