The cache problem:
what is the cache issue? When the browser's input is the same, that is, the requested URL is the same, so that the browser can read cache, the contents of the two, will not interact and the server side.
solution: add a timestamp in the requested url.
by my test, IE, 360 two user name input line will not interact with the server side, firefox even if user name input twice, still can interact with the server side.
the temp value returned by the server in firefox will add 1 at a time, IE, 360 will not change. Therefore, time-stamped stays in these three browsers cache problem.
modify the code:
AJAXServer. Java problems

cache
//cache problem and the test code input the same IE, 360 times not to increase, firefox will add
Integer inte=(Integer) request. GetSession (). The getAttribute (" total ");
int temp=0;
if (inte==null) {
temp=1;
} else {
temp=inte. IntValue () + 1;
}
request. The getSession (). The setAttribute (" total ", temp); .

in AJAXServer Java to join the above code, at the same time out. When the temp variable println added back to the client.
so, if the client's temp value added, it means the client and server interaction, or there will be no.
verify. Js

<! Cache problem, use timestamp to solve - >
//add a timestamp to url, deceive the browser, don't read cache
function convertURL (url) {
//get the timestamp
var timestamp=(new Date (). The valueOf ());
//timestamp information joining together to the url on
//url="AJAXServer"
if (url. IndexOf ("? ") >=0) {
url=url + "&t=" + timestamp;
} else {
url=url + "? T="+ timestamp;
}
the return url;

} function verifyCache () {
var url="AJAXServer? Name=" + $(" #username "). Val ();
=convertURL url (url);//cache
$. Get (url, null, the function (data) {
$(" #result "). The HTML (data);
});
}

because only asked the validation and introduce the cache problem, to illustrate problems, therefore, adopts the way of checking is jquery encapsulation ajax receiving text data on the server.
", "" by the same token, don't forget to modify the ajax, HTML invokes the method, the name changed to the above script verifyCache () Chinese problem:

there are two solutions:
the first: use a encodeURI page end, the server with the String name=new String (old. GetBytes (" iso8859-1"), "utf-8");
1

function verifychinese1 {
var url="AJAXServer? Name=" + encodeURI ($(" #username "). Val ());
=convertURL url (url);//cache
$. Get (url, null, the function (data) {
$(" #result "). The HTML (data);
}); .
", "" verify in js to add the above methods, meanwhile the
String name=new String (old. GetBytes (" iso8859-1"), "utf-8");

add to AJAXServer. The Java class in the proper position. Such as on the PrintWriter can behind the code.
in the same way, with the first way, don't forget to modify the ajax, HTML invokes the method, the name changed to the above script verifychinese1 ()
the second: use two encodeURI page end, the server with the String name=URLDecoder. Decode (old, "utf-8");
2

function verifychinese2 () {
var url="AJAXServer? Name=" + encodeURI (encodeURI ($(" #username "). Val ()));
=convertURL url (url);//cache
$. Get (url, null, the function (data) {
$(" #result "). The HTML (data);
});
}
", "" in verify the js to add the above methods, meanwhile the
String name=URLDecoder. Decode (old," utf-8 ");

add to AJAXServer. The Java class in the proper position. Such as on the PrintWriter can behind the code.
in the same way, in the second way, don't forget to modify the ajax, HTML invokes the method, the name changed to the above script verifychinese2 ()
need source can leave a message.
by learning a few days, the dynamic validation of the basic ajax, follow-up will increase depending on the situation of the corresponding content.

you might be interested in the article:

  • jquery ajax learn notes 3
  • jquery ajax learning notes 2 USES the XMLHttpRequest object responseXML
  • jquery ajax study notes in a


This concludes the body part