SoFunction
Updated on 2025-03-10

Detailed steps to implement refresh-free update data using javascript asp

There is often a situation in programming that is that it is impossible to know what data the user will need in advance, and it must be selected based on the user and then re-extracted from the server and fed back to the user. For example, in a simple situation, after the user selects a province, we will immediately redisplay all cities in the province in the city. In this case, the entire page needs to be refreshed before re-reading, but this is not only inefficient, but also inelegant. In fact, using JavaScript combined with micro-software XMLHTTP objects, we can read data from the server without refreshing it, which seems both professional and efficient.
Let’s demonstrate this technique using a situation where the user is registered.
'Program design: Global Wanwei, professional virtual hosting and domain name registration service provider
'Website:
'This program is an original program of Global World Wide, so if you need to reprint it, please indicate the source, thank you.
'The above information is an integral part of the article's main text, so if you want to reprint this article, you must retain the above information.

1. First, create a file on the server to detect whether the user exists, and feedback 0 and 1 respectively according to whether the user exists.
u_name=("u_name")
if u_name existed then
 "0"
else
 "1"
end if
2. Client HTML design:
1. JavaScript code
<script language=javascript>
function check_user_exists(form){
u_name=form.u_name.value;
if (u_name==null||u_name==''){
alert("Please enter your username");
return false;
}
infoBoard=("checkInfo");
='Query...';
myurl=+"//"++"/?u_name="+u_name;
retCode=openUrl(myurl);
switch(retCode){
case "-2":
='<font color=red>Sorry</font>, the query failed'; break;
case "1":
='<font color=red>Congratulations</font>,'+u_name+' can be used';break;
case "0":
='<font color=red>Sorry</font>, the user name '+u_name+' has been used';
}
return;
}

function openurl(/url){
var objxml=new ActiveXObject("")
("GET",url,false);
();
retInfo=;
if (=="200"){
return retInfo;
}
else{
return "-2";
}
}
</script>
2. HTML form design:
<form name=form1 action="" method="post">
<input type=text name=u_name><span ></span><input type=button name=checkuser value="Detection of whether the user exists" onClick="check_user_exists();">
</form>

After the above three steps, a data update program that does not require page refresh is completed (demo address: http:///reg). According to this method, many cool applications can be realized:)