-1

I have the following code onClick of a button

function Test(){
 $.ajax({
 type: 'POST',
 url: 'testme?userId=
 <%=session.getAttribute("username").toString()%>',
 load: 'test.jsp'
 });
}

What I am trying to achieve with the above is after passing the values to server, I would like to refresh the page using ajax. However page is not getting refreshed.

How can I resolve this problem?

Edit 1

<div id="myDiv">
<iframe src='testiframe.jsp?prod=<%=request.getParameter("prod")%>'
id="maxim" width="100%" 
frameborder="0" height="190"></iframe>
</div>  
Jacob
  • 14,463
  • 65
  • 207
  • 320
  • 1
    Which part of the page do you want refreshed? It is simply a matter of taking the returned data from the Ajax call and replacing part (or all) of your page. e.g. You can return the current page and replace all HTML, or you can (should) return just the part that changes and replace that. Ajax is all about changing the minimum (and sending the least amount of data). – iCollect.it Ltd Apr 08 '14 at 08:37
  • @TrueBlueAussie My page has two parts, one which having the button and below part is an iframe. I would like to refresh iframe part. – Jacob Apr 08 '14 at 08:42

3 Answers3

1

Use window.location.href in your ajax success()

function Test(){
  $.ajax({
   type: 'POST',
   url: 'testme?userId=<%=session.getAttribute("username").toString()%>',
   success: function(){
   window.location.href= 'test.jsp';
  }
});
}
Shijin TR
  • 7,516
  • 10
  • 55
  • 122
1

Assuming, you have myContentDiv div to refresh the new content comes from server, then update its content in success callback. By default, dataType is html, mean you will be returning a html content from server

function Test(){
 $.ajax({
   type: 'POST',
   url: 'test.jsp?userId=<%=session.getAttribute("username").toString()%>',
   success: function(data){
      $('#myContentDiv').html(data);
   }
  });
}
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
  • Part I would like to refresh is an iframe which is defined inside div. I would like to pass a parameter as well to iframe page, else page will not reload. I have edited my question with iframe part. – Jacob Apr 08 '14 at 08:57
1

If you are using ajax, is because you don't want to refresh the page. But for some reason if it is what you want, you can do it like so:

function Test(){
    $.ajax({
    type: 'POST',
    url: 'testme?userId=<%=session.getAttribute("username").toString()%>',
    success: function(){
        location.reload();
    }
 });
}
cor
  • 3,323
  • 25
  • 46