- 论坛徽章:
- 0
|
- %@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxDem1.aspx.cs" Inherits="AjaxDemo1.AjaxDem1" %>
- <!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 runat="server">
- <title></title>
- <script type="text/javascript">
- window.onload = function () {
- //1.获取 a 节点并为其添加 onclick 响应方法
- document.getElementsByTagName("a")[0].onclick = function () {
- //2.创建一个 XMLHttpRequest 对象
- var request = new XMLHttpRequest();
- //3.准备发送请求的数据对象:URL
- var url = this.href;
- var method = "GET";
- //4.调用 XMLHttpRequest 对象的 open 方法
- request.open(method, url);
- //5.调用 XMLHttpRequest 对象的 send 方法
- request.send(null);
- //6.调用 XMLHttpRequest 对象的 onreadystatechange 响应函数
- request.onreadystatechange = function () {
- //7.判断响应是否完成:XMLHttpRequest 对象的 readystate 属性值为 4 表示响应完成
- if (request.readystate == 4) {
- //8.在判断响应是否可用: XMLHttpRequest 对象的 status 属性值为 200 表示响应正常
- alert(request.status);
- if (request.status == 200 && request.status == 304) {
- //9.打印响应结果:responseText
- alert(request.responseText);
- }
- }
- }
- //10.取消 a 节点的默认行为
- return false;
- }
- }
- </script>
- </head>
- <body>
- <a id="a1" href="hello.txt">点击我显示hello文本文件内容</a>
- </body>
- </html>
复制代码 从if那测试得到的值就是undefined 恩么回事 这段代码我看视频上用java可以执行 但是用。net写 就出错了, 前台代码不都是通用的吗? |
|