1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>异步服务器连接</title> 6 ?7 <script language="javascript"> 8 var xmlhttp; 9 function createXMLHttpRequest(){10 ????if(window.ActiveXObject)11 ???????xmlhttp = new ActiveXObject(‘Microsoft.XMLHTTP‘);12 ?????else if(window.XMLHttpRequest)13 ?????xmlhttp = new XMLHttpRequest();14 }15 16 function test(){17 ????createXMLHttpRequest();18 ????xmlhttp.open(‘GET‘,‘10.1.aspx‘,true);19 ????20 ????xmlhttp.onreadystatechange = function HandleStateChang(){21 ????if(xmlhttp.readyState==4&& xmlhttp.status==200)22 ????????alert(‘服务器返回的结果为‘ + xmlhttp.responseText);23 ????????}24 ????xmlhttp.send(null);25 }26 </script>27 </head>28 29 <body>30 <input type="button" value="测试是否连接成功" onClick="test()" />31 </body>32 </html>
服务器代码采用.aspx文件
代码如下:
1 <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>2 <%@Import Namespace="System.Data"%>3 <%4 ??Response.Write("连接成功");5 %>;
但是测试过程中出现了很多问题现列出解决方法
1.运行aspx文件需在dw中创建站点和相对应的服务器
如果没有搭建网站可进行如下操作
1.打开控制面板->系统和安全->管理工具->IIS
若未发现IIS 打开控制面板的“程序”->Windows启用。。->
打开IIS管理器 选中网站 点击右键“添加网站”
点击“连接为”
设置凭据出 填写 自己的开机账号密码(其它博主如此的标注)
添加完毕后点击测试
如果再次运行文件出现报错 404.17请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
如果没有发现 .aspx扩展名 可在右侧进行自主添加 添加后默认true(楼楼就是自己碰到的这个问题)
dw cs6 ajax ?异步连接测试
原文地址:https://www.cnblogs.com/qianqianblog/p/10291666.html