Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我无法运行ajax示例_Asp.net_Ajax - Fatal编程技术网

Asp.net 我无法运行ajax示例

Asp.net 我无法运行ajax示例,asp.net,ajax,Asp.net,Ajax,大家好,我有以下代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <script type="text/javascript"> function showHint(s

大家好,我有以下代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
 <script type="text/javascript">
 function showHint(str)
 {
    var xmlhttp
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest()
    }
    else
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        xmlhttp.onreadystatechange = function()
        {   
        if (xmlhttp.readystate == 4 && xmlhttp.status == 200)
        {
            document.getElementById('hint').innerHTML= xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","sample.aspx?q=" + str ,true)
        xmlhttp.send()
 }
 </script>
 </head>
 <body>
Type here: <input type="text" id="txt" onKeyUp = "showHint(this.value)"/>  
Suggestion here: <div id="hint"></div>
 </body>
</html>

新文件
函数showHint(str)
{
var xmlhttp
if(window.XMLHttpRequest)
{
xmlhttp=newxmlhttprequest()
}
其他的
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
xmlhttp.onreadystatechange=函数()
{   
if(xmlhttp.readystate==4&&xmlhttp.status==200)
{
document.getElementById('hint').innerHTML=xmlhttp.responseText;
}
}
open(“GET”,“sample.aspx?q=“+str,true”)
xmlhttp.send()
}
在此处键入:
建议如下:
但是这个例子不起作用。它说访问被拒绝(脚本错误) 如何解决这个问题。。! 我的aspx页面如下所示

<%
response.expires=-1
dim a(30)
'Fill up array with names
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"
a(11)="Kitty"
a(12)="Linda"
a(13)="Nina"
a(14)="Ophelia"
a(15)="Petunia"
a(16)="Amanda"
a(17)="Raquel"
a(18)="Cindy"
a(19)="Doris"
a(20)="Eve"
a(21)="Evita"
a(22)="Sunniva"
a(23)="Tove"
a(24)="Unni"
a(25)="Violet"
a(26)="Liza"
a(27)="Elizabeth"
a(28)="Ellen"
a(29)="Wenche"
a(30)="Vicky"

'get the q parameter from URL
q=ucase(request.querystring("q"))

'lookup all hints from array if length of q>0
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

'Output "no suggestion" if no hint were found
'or output the correct values
if hint="" then
  response.write("no suggestion")
else
  response.write(hint)
end if
%>

您有两个不同的问题。首先,sample.aspx应该是sample.asp,因为它是一个经典的asp页面,而不是.Net asp页面。还要确保更改
xmlhttp.open
方法中的路径

其次,
xmlhttp.readystate
应该是
xmlhttp.readystate
——注意大写字母S。我花了一点时间才弄清楚这一部分。


问题可能是您正在file://protocol中运行HTML文件。据我所知,像.php和.asp这样的服务器文件在file://协议中不起作用。
如果您真的希望这样做,请尝试设置并将文件放入服务器文件夹中。如果您使用的是Linux,那么它就在/var/www中,对于其他操作系统,我不太确定。
另外,虽然这与此无关,但我建议您将Doctype更改为
,因为这是现在的标准。很抱歉你不必这么做。
祝你好运