سؤال

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>  
هل كانت مفيدة؟

المحلول

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();
    }
 });
}

نصائح أخرى

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';
  }
});
}

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);
   }
  });
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top