質問

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