Search code examples
javaajaxinternet-explorer-7struts

Ajax not reloading the jsp on success


Environment: IE7, jQuery 1.1 , Struts 1

Context: Making an ajax call to a Java method which, and the end, reloads the same jsp.

The steps are: jsp A -->request to java method-->doing some stuff-->ActionForward to jsp A, which is returned in the response. Actually I'm doing this with a single request using location.href and it's working properly.

Now I need to handle multiple requests and conditions and the only way I thought was by using nested ajax calls with async:false, but that's not the point.

The problem is ajax does not reloads the jsp like location.href does. This jsp is just a smaller part of the main jsp, so I'm not reloading the whole jsp. I guess I have to handle the response in some way, but how?

Call with location.href:

<script>
function myFunction(){
    location.href = 'path/to/java/method=with_some_parameters';
}
</script>

Call with ajax:

<script>
 function myFunction(){
  jQuery.ajax({
   url:'path/to/java/method=with_some_parameters'
   async:false,
   success:function(data){
   //nested ajax

   }
  });
 }
</script>

There is a similiar question: Reload a page after jquery ajax call, but it didn't help.

Another: How to manage a redirect request after a jQuery Ajax call, this looks better. I'm trying some things.


Solution

  • As I got the full html in the response ('data' in my case), It worked using

    function myFunction(){
      jQuery.ajax({
       url:'path/to/java/method=with_some_parameters'
       async:false,
       success:function(data){
         document.open();
         document.write(data);
         document.close();
         //nested ajax
    
       }
      });
     }
    

    Source Replacing Entire Page Including Head Using Javascript