懂ajax javascript的进。。。。。。简单的找错误。。。。

来源:百度知道 编辑:UC知道 时间:2024/06/20 11:20:47
今天刚开始学 ajax,比着教材写了几句代码如下。。。。

aa.asp 是ajax页。
bb.asp是服务器页。

我的目的很简单,就是在ajax页 事件触发时,用alert弹出 bb.asp页输出的信息,但是结果只出现一个没有任何内容的alert对话框,请大家帮我看看哪错了。。谢谢 。。

这是aa.asp页。。。。
<html>
<head>
<script language="javascript">
var xmlhttp;
function creatXMLHttpRequest(){
if(window.ActiveXObject)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
}

function startrequest(){
creatXMLHttpRequest();
xmlhttp.open("GET","bb.asp",true);

xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
alert(xmlhttp.responseText);
}
xmlhttp.send(null);
}
</script>
</head>
<body>
<form>
<input type="text" onBlur="

那就是字符编码的问题了,你在bb.asp

加上 Response.Charset = "gb2312"

gb2312 换成和你页面字符编码一致的就行了。

是不是两个页面不在同一个文件夹下?

估计是URL是要写绝对路径。。

你在地址栏里直接打 bb.asp ,看看会不会输出 你好呀,

function creatXMLHttpRequest(){
if(window.ActiveXObject)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
}

把你上面的那个改成下面那样试试:

function creatXMLHttpRequest(){

try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
// Internet Explorer
xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e)
{
alert('Your browser does not support AJAX!');
return fa