1

Background

I am using spring MVC with hibernate

jquery Code snippet

$(document).ready(function() {
    $( "#dialog" ).dialog();
    $('#tableDiv').load('genCityInqGV.htm?type=0&number=1');
    $( "#dialog" ).dialog('close');
} );

In @Controller

    @RequestMapping(value = "/genCityInqGV", method = RequestMethod.GET)
public String genCityInqGV() {
    try {
        while(true){
            System.out.println("Print");
        }
    } catch (Exception ex) {
        log.error("Exception.." + ex);
    }

    return "gen/genCityInqGV";
}

In controller I write finite loop to check whether dialog functionality working or not ? but dialog still going to close. this means that following statement execute.

$( "#dialog" ).dialog('close');

after the following one

$('#tableDiv').load('genCityInqGV.htm?type=0&number=1');

when I check the screen the following statement still print

System.out.println("Print");

Even the process of load function in back-end still processing , so why dialog('close') statement execute.

Update me!

Shahid Ghafoor
  • 2,991
  • 17
  • 68
  • 123

1 Answers1

1

What was your code like before using Spring MVC, because the principle should remain the same.

jquery load() loads asynchronously, so the next statement can very well be executed before the load is finished.

Maybe you can get around this using a callback after the load (perhaps this is what you did before?). Please take a look at How to load page synchronously using jQuery.

try:

$('#tableDiv').load('genCityInqGV.htm?type=0&number=1', function(){
    $( "#dialog" ).dialog('close');
});
Community
  • 1
  • 1
ljgw
  • 2,751
  • 1
  • 20
  • 39
  • jquery load() loads asynchronously, so the next statement can very well be executed before the load is finished. with this context , how can I close the dialog only if load statement finish execution! ? – Shahid Ghafoor Jun 01 '13 at 15:37
  • I have edited my anwswer to include a bit of example code. I hope this works for you! – ljgw Jun 01 '13 at 15:45
  • yes solved ! I explore my old backup , which is simple web! the scenario was different , but I was confused – Shahid Ghafoor Jun 01 '13 at 15:46