当前位置: 代码迷 >> ASP.NET >> xmlhttp.status一直为404 咋回事
  详细解决方案

xmlhttp.status一直为404 咋回事

热度:9470   发布时间:2013-02-25 00:00:00.0
xmlhttp.status一直为404 怎么回事
HTML代码
<!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>
  <script type="text/javascript">
  function showCustomer(str) {
  var xmlhttp;
  if (str == "") {
  document.getElementById("txtHint").innerHTML = "";
  return;
  }
  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp = new XMLHttpRequest();
  }
  else {// code for IE6, IE5
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function () {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
  }
  }
  xmlhttp.open("GET", "~/ajax/getcustomer.asp?q=" + str, true);
  xmlhttp.send(null);
  }
</script>
</head>
<body>
  <form action="" style="margin-top:15px;"> 
  <label>请选择一位客户:
  <select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;">
  <option value="ANATR">Apple Computer, Inc.</option>
  <option value="ANTON ">BAIDU, Inc</option>
  <option value="Canon">Canon USA, Inc.</option>
  <option value="Google">Google, Inc.</option>
  <option value="Nokia">Nokia Corporation</option>
  <option value="SONY">Sony Corporation of America</option>
  </select>
  </label>
  </form>
  <br />
  <div id="txtHint">客户信息将在此处列出 ...</div>
</body>
</html>


ASP代码:

<html>
<body>
<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"




Dim sConnection, objConn , rs
sConnection = "DRIVER=={SQL Server}; SERVER=localhost; DATABASE=clients; UID=sa;PWD=123456"

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open(sConnection)

Set rs = objConn.Execute(sql)






response.write("<table>")
do until rs.EOF
  for each x in rs.Fields
  response.write("<tr><td><b>" & x.name & "</b></td>")
  response.write("<td>" & x.value & "</td></tr>")
  next
  rs.MoveNext
loop
response.write("</table>")
rs.close
conn.close
%>
</body>
</html>


------解决方案--------------------------------------------------------
xmlhttp.open("GET", "~/ajax/getcustomer.asp?q=" + str, true);
这里的ajax处理程序的路径是否正确
------解决方案--------------------------------------------------------
输出信息看看
------解决方案--------------------------------------------------------
  相关解决方案