开发者

i am unable to run ajax example

Hello all i have the following code

<!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">开发者_Python百科</div>
 </body>
</html>

but this example not working..it is saying access is denied (script error) How to solve this..! My aspx page follows like this

<%
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
%>


You have two separate issues. First, your sample.aspx should be sample.asp, as it is a classic asp page, not a .Net asp page. Make sure you change the path in the xmlhttp.open method as well.

Second, xmlhttp.readystate should be xmlhttp.readyState - note the capital S. Took me a bit to figure that part out.



The problem might be that you're running the HTML file in file:// protocol. As far as I'm aware, server files like .php & .asp don't work in file:// protocol.
If you really want this to work, try setting up Apache and put your files inside your server folder. If you're in Linux, it's in /var/www, with other operating systems I'm not so sure.
Also, thought it's unrelated, I would recommend changing your Doctype to <!DOCTYPE html> as it is the standard now. Sorry. You don't have to.
Best of luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜