我在ajax调用open("GET",url,true)时,这一行总是提示“拒绝访问”,请问可能是那些原因?代码应该木有问
用ajax做一个注册检测的东西,代码在http://www.w3school.com.cn/ajax/ajax_source.asp,效果演示:http://www.w3...
用ajax做一个注册检测的东西,代码在http://www.w3school.com.cn/ajax/ajax_source.asp,
效果演示:http://www.w3school.com.cn/tiy/t.asp?f=ajax_httpsuggest
我自己把代码复制粘贴后就出现了“拒绝访问”的错误(我用的phpstudyadmin服务器)
代码:
共有三个文件:eee.html,clienthint.js,gethint.asp
-----------------------------------------------------------------------------------------------------------
//----eee.html
<head>
<script src="clienthint.js"></script>
</head>
<body><form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p> </body>
</html>
-----------------------------------------------------------------------------------------------------------
//--------------clienthint.js
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="gethint.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
-----------------------------------------------------------------------------------------------------------//---------gethint.asp
<body>
<%
response.expires=-1
dim a(10)
'用名字为数组赋值
a(1)="Anna"
a(2)="Brittany"
a(3)="Cinderella"
a(4)="Diana"
a(5)="Eva"
a(6)="Fiona"
a(7)="Gunda"
a(8)="Hege"
a(9)="Inga"
a(10)="Johanna"
'如果q的长度大于0,则查找所有的hint
if len(q)>0 then
hint=""
for i=1 to 30
if q=ucase(mid(a(i),1,len(q))) then
if hint="" then
hint=a(i)
else
hint=hint & " , " & a(i)
end if
end if
next
end if
'如果找不到hint,则输出"no suggestion"
'或者输出正确的值
if hint="" then
response.write("no suggestion")
else
response.write(hint)
end if
%>
</body>
</html>
是服务器的问题吗?我之前试过jsp文件的时候也有相同的错误,这个问题已经纠结我好几天了,我是个初学者 展开
效果演示:http://www.w3school.com.cn/tiy/t.asp?f=ajax_httpsuggest
我自己把代码复制粘贴后就出现了“拒绝访问”的错误(我用的phpstudyadmin服务器)
代码:
共有三个文件:eee.html,clienthint.js,gethint.asp
-----------------------------------------------------------------------------------------------------------
//----eee.html
<head>
<script src="clienthint.js"></script>
</head>
<body><form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p> </body>
</html>
-----------------------------------------------------------------------------------------------------------
//--------------clienthint.js
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="gethint.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
-----------------------------------------------------------------------------------------------------------//---------gethint.asp
<body>
<%
response.expires=-1
dim a(10)
'用名字为数组赋值
a(1)="Anna"
a(2)="Brittany"
a(3)="Cinderella"
a(4)="Diana"
a(5)="Eva"
a(6)="Fiona"
a(7)="Gunda"
a(8)="Hege"
a(9)="Inga"
a(10)="Johanna"
'如果q的长度大于0,则查找所有的hint
if len(q)>0 then
hint=""
for i=1 to 30
if q=ucase(mid(a(i),1,len(q))) then
if hint="" then
hint=a(i)
else
hint=hint & " , " & a(i)
end if
end if
next
end if
'如果找不到hint,则输出"no suggestion"
'或者输出正确的值
if hint="" then
response.write("no suggestion")
else
response.write(hint)
end if
%>
</body>
</html>
是服务器的问题吗?我之前试过jsp文件的时候也有相同的错误,这个问题已经纠结我好几天了,我是个初学者 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询