문제

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