Ajax中的XMLHttpRequest
来源:互联网 发布:java中demo是什么意思 编辑:程序博客网 时间:2024/06/04 08:42
记录下今天所学的Ajax基础
javascript code
window.onload = initAll;var varAjax;function initAll() { document.getElementById("goAjax").onclick = initGoAjax;}function initGoAjax() { if (window.XMLHttpRequest) { //浏览器是否支持如果支持就创建 varAjax = new XMLHttpRequest; } else { varAjax = new ActiveXObject("Micorsoft.XMLHTTP"); //使用ActiveXObject创建 } varAjax.onreadystatechange = getAjax; //<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">指定当readyState属性改变时的事件处理句柄</span> varAjax.open("GET", "us-states.xml?g="+Math.random(), true); //添加一个唯一ID使获取的文件不是缓存的文件 其实应该添加GUID varAjax.send(null); return false;}function getAjax() { if (varAjax.readyState == 4 && varAjax.status == 200) { //当前的请求状态和当前的请求状态码 if (varAjax.responseXML && varAjax.responseXML.childNodes.length > 0) { var outMsg = getText(varAjax.responseXML.getElementsByTagName("choices")[0]); document.getElementById("AjaxDiv").innerHTML = outMsg; } else document.getElementById("AjaxDiv").innerHTML = varAjax.responseText; }}function getText(inVal) { if (inVal.textContent) { return inVal.textContent; } else return inVal.text;}html code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="Ajax" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="js/Ajax.js"></script> <link href="css/Ajax.css" rel="stylesheet" /></head><body> <p> <a id="makeTextRequest" href="gAddress.txt">Request a text file</a><br> <a id="makeXMLRequest" href="us-states.xml">Request an XML file</a> </p> <div id="updateArea"></div></body></html>
0 0
- AJAX中的XmlHttpRequest
- AJAX中的XMLHttpRequest对象
- Ajax中的XMLHttpRequest
- AJAX中的XMLHttpRequest对象
- ajax中的xmlhttprequest对象介绍
- 创建ajax中的xmlhttprequest对象
- Ajax和XML中的XMLHttpRequest
- Ajax中的内置对象XMLHttpRequest
- Ajax中的XMLHttpRequest对象详解
- Ajax中的XMLHttpRequest对象详解
- XMLHttpRequest 传说中的Ajax原型
- Ajax中的XMLHttpRequest对象详解
- Ajax中的XMLHttpRequest对象详解
- 详解AJAX核心中的XMLHttpRequest对象
- 详解AJAX核心中的XMLHttpRequest对象
- 详解AJAX核心中的XMLHttpRequest对象
- Js中的Ajax XMLHttpRequest的创建
- ajax应用中的xmlHttpRequest-属性和方法
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- notepad++ 中增加lua语法检查快捷键
- bzoj3781: 小B的询问 莫队算法
- 关于Struts中*.do的问题
- 低功耗蓝牙4.0BLE编程-nrf51822开发(1)
- Ajax中的XMLHttpRequest
- 删除子字符串
- opencv中Mat的使用注意事项
- Redis基础之事务
- LeetCode OJ 之 Path Sum II (路径和 - 二)
- MD5加密
- 硬件工程师面试集锦 模拟电路 数字电路 IC设计基础 单片机 信号与系统 DSP 嵌入式
- 基于Cocos2d-x3.2的虚拟摇杆实现及操控角色移动
- 获取上级ViewController