欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Js获取asp页面返回的值(加载值)实现代码

程序员文章站 2022-08-10 18:26:51
复制代码 代码如下:
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gbk" />
<title>getting server side data using ajax</title>
</head>
<script>
function creat_object() {
var xmlhttp;
if (!xmlhttp && typeof xmlhttprequest != 'undefined') {
try {
xmlhttp = new xmlhttprequest();
}
catch (e) {
alert("your browser is not supporting xmlhttprequest"); <br> xmlhttp = false;
}
}
else {
xmlhttp = new activexobject("microsoft.xmlhttp");
}
return xmlhttp;
}
var request = creat_object();
function sever_interaction() {
if (request.readystate == 1) {
document.getelementbyid('aja_cnts').value = '';
document.getelementbyid('aja_cnts').value = 'loading...';
}
if (request.readystate == 4) {
var answer = request.responsetext;
document.getelementbyid('aja_cnts').value = '';
document.getelementbyid('aja_cnts').value = answer;
}
}
function call_server() {
request.open("get", "response.asp");
request.onreadystatechange = sever_interaction; request.send('');
}
</script>
<body>
<input type="button" name="btnload" id="btnload" value="点击加载" onclick="call_server();" />
<input type="text" style=" width:265px; height:68px;" id="aja_cnts" />
</body>
</html>

获取页面response.asp代码:document.getelementbyid('aja_cnts').value
response.asp代码示例:
复制代码 代码如下:

<%
response.write "您好!欢迎光临悠9小店!"
response.write "我们的网址是:http://you9luck.taobao.com"
%>