2014年1月7日星期二

Use Ajax to access servlet appear a strange question

Today, the project found that when doing servlet using Ajax connection , only the first run when connected to the servlet code , like a long time have not figured out , please help to see if this is in the end is how is it ?
I put the key code to paste ,

<body>
   <a href="javascript:del()">删除</a>
  </body>
  <script type="text/javascript">
  function del(){
var url="DeleteServlet";
xmlHttp=createXmlHttpRequest();
xmlHttp.onreadystatechange=process;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
  }
function process(){
if(xmlHttp.readyState==4){
if (xmlHttp.status==200) {
alert("x");
}
}
}
后面 省略 ……

DeleteServlet in on the word , System.out.println (" the delete ! " ) ;
Whenever I click Delete , the first played in the console ' executive Delete' and pop 'x', the second and third time , the console did not print out content, but 'x' was able to pop up in the end is how is this all about?
------ Solution ---------------------------------------- ----
delete no parameters ? Followed by a timestamp look .
------ Solution ---------------------------------------- ----
Ajax tips , followed by a time stamp prevents the browser cache data
------ For reference only ---------------- -----------------------
which property will not be xmlHttp is not set
------ For reference only ---------------------------------------
  The reply was deleted administrator at 2014-01-06 08:51:15

------ For reference only ---------------------------------- -----

the delete into delete the servlet code execution every time , I found Ajax request must not be the same for each url servlet code will be executed if the same would only perform the first
- ----- For reference only ---------------------------------------
you mean they do not write synchronization function , write directly configured servlet that DeleteServlet?
------ For reference only -------------------------------------- -

thanks, should be the caching issues, together with a time stamp after each will execute the code inside a servlet
------ For reference only ------ ---------------------------------

the delete into delete the servlet code execution every time , I found Ajax request url must not be the same for each servlet code will be executed if the same would only perform for the first time  
behind url add a new Date ()

没有评论:

发表评论