The very first thing that we need to be able to do in order to retrieve something from the server to update the current web page (without reloading the whole page) is to create the object that will perform the processing for us. Modern browsers have a predefined class called XMLHttpRequest that we can use to define our object directly. Internet Explorer has provided five different interfaces to provide us with the functionality that we need each of which is accessed via AxtiveX. As each new version has improved the functioning of the object we want to grab the most recent version that is installed in the browser.
function createXMLHttp() {
if (typeof XMLHttpRequest != 'undefined')
return new XMLHttpRequest();
else if (window.ActiveXObject) {
var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp",
"MSXML2.XmlHttp.3.0";, "MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.5.0"];
for (var i = avers.length -1; i >= 0; i--) {
try {
httpObj = new ActiveXObject(avers[i]);
return httpObj;
} catch(e) {}
}
}
throw new Error('XMLHttp (AJAX) not supported');
}
var ajaxObj = createXMLHttp();
This code starts by checking if the XMLHttpRequest class exists. If it does then we use that to create our object. If it doesn't then we check if ActiveX is supported (which means that the browser is running Internet Explorer on Windows with ActiveX enabled). If it is then we try to create our object using the latest XMLHttp version (version 5.0). If that fails then we work our way back through the array trying each earlier version in turn until we find one that is installed in the browser and which therefore allows us to create our object. If all of those attempts fail or if neither XMLHttpRequest or ActiveX are supported then we throw an error to indicate that AJAX is not supported in this browser.
分享到:
相关推荐
XMLHttpRequest.Status多种状态的含义 xmlHttpRequest的status的值的含义 xmlHttpRequest对象的status代表当前http请求的状态,是一个长整型数据,现在介绍一下它的含义。 http请求状态及其含义表 1xx - 信息...
[转]XMLHTTPRequest的属性和方法简介
博文链接:https://lengue.iteye.com/blog/163349
如果你使用 XMLHttpRequest 来获得一个远程的 XML 文档的内容,responseXML 属性将会是一个由 XML 文档解析而来的 DOM 对象,这很难被操作和分析。这里有五种主要的分析 XML 文档的方式: 1.使用 XPath 定位到文档...
前端JS中使用XMLHttpRequest 2上传图片到服务器,PC端和大部分手机上都正常,但在少部分安卓手机上上传失败,服务器上查看图片,显示字节数为0。下面是上传图片的核心代码: HTML <input type="file" id=...
被请求者XMLHttpRequest + FormData 包装器,可轻松嵌入 AJAX。应用程序接口新的创建一个新的 Requeste 实例。 new Requeste ( string method , string uri ) ; 例子: var req = new Requeste ( 'GET' , '...
xmlHttpRequest对象的status代表当前http请求的状态,是一个长整型数据,现在介绍一下它的含义。 http请求状态及其含义表 1xx – 信息提示 100 – 初始的请求已经接受,客户应当继续发送请求的其余部分。(HTTP 1.1...
教程特性√从浏览器创建XMLHttpRequest √支持Promise API √拦截请求和响应√转换请求和响应数据√取消请求√自动转换JSON数据√客户端支持防止XSRF开始# 安装依赖yarn# 开发及调试yarn dev# 构建yarn build# 测试...
XmlHttp是一套可以在Javascript、VbScript、Jscript等脚本语言中通过http协议传送或从接收XML及其他数据的一套API。XmlHttp最大的用处是可以更新网页的部分内容而不需要刷新... 1、XMLHTTPRequest对象什么是?最通用的
西里尔·佩雷拉 原型 JavaScript 框架,版本 1.5.0 (c) by Sam Stephenson Funkychat 以知识共享许可发布 EN FR PT ... 您可以在线与人聊天, 表情符号允许使用快捷键,如“:)” 不使用标签直接转换url ...
AJAX 指异步 JavaScript 及 XML(Asynchronous JavaScript And XML)。 国 [使用ajax 构建应用程序] ...简而言之,XmlHttpRequest使您可以使用JavaScript向服务器提出请求并处理响应,而不阻塞用户。
主页: : ... 该类还支持Flash上传器和XMLHttpRequest。 该类可用于PHP 5.3 +,PHP 7和PHP 8(将1.x版本用于PHP 4支持),并且其错误消息可以随意进行本地化。 通过作曲家安装 编辑您的composer.
第一章.文本特效类 第二章.图片特效类 第三章....第四章....第五章....第六章....第七章....第八章....第九章....第十章....第十一章....第十二章....第十三章....第十五章.Ajax与XMLHttpRequest 第十六章.JavaScript连接数据库实例
javascirpt的一些经典特效 第一章.文本特效类 第二章.图片特效类 第三章....第四章....第五章....第六章....第七章....第八章....第九章....第十章....第十五章.Ajax与XMLHttpRequest 第十六章.JavaScript连接数据库实例
或者使用服务器代理,代理XMLHttpRequest文件 AJAX是基于现有的Internet标准,并且联合使用它们: XMLHttpRequest 对象 (异步的与服务器交换数据) JavaScript/DOM (信息显示/交互) CSS (给数据定义样式) XML (作为...
axios是基于promise的用于浏览器和nodejs的HTTP...从浏览器中创建XMLHttpRequest; 从nodejs发出http请求 支持promiseAPI 拦截 请求和响应 转换请求和响应数据 取消请求 自动转换JSON数据 客户端支持防止CSRF/XSRF攻击
axios 是一个基于Promise 用于浏览器... 从浏览器中创建 XMLHttpRequest 从 node.js 发出 http 请求 支持 Promise API 拦截请求和响应 转换请求和响应数据 取消请求 自动转换JSON数据 客户端支持防止 CSRF/XSRF