Javascript: You can use Javascript to update data without refreshing. In the Javascript tutorial program design, you will often encounter a situation where you cannot know the data you need in advance, data must be extracted from the server and then fed back to the user based on the user selection. For example, if you select a province, we will immediately display all the cities in the province. In this case, you need to refresh the entire page before reading it again. However, this is not only inefficient, but also not elegant. In fact, we can use javascript to combine Microsoft's XMLHTTP object. We don't need to refresh it. We can read the data from the server just a little bit, which is both professional and efficient.
Next we will demonstrate this technology by verifying whether a user is registered.
'Program design: world wide, professional domain name registration, virtual host service provider
'URL: http://www.netInter.cn
'The program is a hichina program. If you need to reprint it, please indicate the source. Thank you.
'The above information is an integral part of the text. Therefore, if you want to reprint this article, you must keep the above information.
1. First, create a CheckUser. asp file on the server to check whether the user exists. Based on whether the user exists, report 0 and 1 respectively.
The following is a reference clip: U_name = Request. QueryString ("u_name ") If u_name has then Response. write "0" Else Response. write "1" End if |
2. Client HTML design:
I. JavaScript code
The following is a reference clip: Function check_user_exists (form ){ U_name = form. u_name.value; If (u_name = null | u_name = ''){ Alert ("Enter the user name "); Return false; } InfoBoard = document. getElementById ("checkInfo "); InfoBoard. innerText = 'querying ...'; Myurl = location. protocol + "//" + location. hostname + "/CheckUser. asp? U_name = "+ u_name; RetCode = openUrl (myurl ); Switch (retCode ){ Case "-2 ": InfoBoard. innerHTML = 'Sorry, query failed'; break; Case "1 ": InfoBoard. innerHTML = 'Congratulations, '+ u_name +' Can Be Used '; break; Case "0 ": InfoBoard. innerHTML = 'Sorry, Username '+ u_name +' already used '; } Return; } Function openurl (/url ){ Var objxml = new ActiveXObject ("Microsoft. XMLHttp ") Objxml. open ("GET", url, false ); Objxml. send (); RetInfo = objxml. responseText; If (objxml. status = "200 "){ Return retInfo; } Else { Return "-2 "; } } Script |
Ii. HTML form design:
The following is a reference clip:
|
After the above three steps, a page does not need to refresh the data update program completed (Demo address: http://www.web9898.cn/reg), according to this method, you can achieve a lot of will be cool application :)