XMLHttp小手册,原生ajax参考手册
个人做java ee开发,在一般的公司里上班,做的是一般的网站。
1.如果经常使用jquery等框架进行异步调用,最主要的不是了解jquery怎么用,而是了解http协议。
2.为了了解http协议,可以使用火狐的控制台F12,谷歌的控制台F12查看responseHeader,requestHeader.在IE下,可以使用HttpWatch Professional这个工具。
3.如果要系统了解原生的ajax请求,可以访问网站 xmlHttp小手册 http://fireyy.com/doc/xmlhttp/xmlhttprequest.html
<html>
<head>
<script type="text/javascript">
var xmlHttp;
function loadXMLDoc(url){
xmlHttp=null;
if(window.XMLHttpRequest){
//IE7,FireFox,Opear,等浏览器
xmlHttp=new XMLHttpRequest();
}else if(window.ActiveXObject){
//IE5,IE6浏览器
xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
}
if(xmlHttp!=null){
xmlHttp.onreadystatechange=state_Change;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}else{
alert("您的浏览器不支持xmlHttp");
}
}
//状态变化时调用的回调函数
function state_Change(){
//4--加载完毕
if(xmlHttp.readyState==4){
//200 --OK
if(xmlHttp.status==200){
document.getElmentById('').innerHTML=xmlHttp.status;
doucment.getElmentById().innerHTML=XMLHttp.statusText;
doucment.getElmentById().innerHTML=xmlHttp.responseText;
}else{
alert('取回数据XML错误 状态为: '+xmlHttp.statusText);
}
}
} </script>
</head> <body>
<h2>使用HttpRequest对象</h2> <p><b>Status:</b>
<span id="A1"></span>
</p> <p><b>Status text:</b>
<span id="A2"></span>
</p> <p><b>Response:</b>
<br/><span id="A3"></span>
</p> <button onclick="loadXMLDoc('http://www.w3school.com.cn/example/xdom/note.xml')">Get XML</button>
</body>
上面的代码直接拿来运行是不行的,打开谷歌浏览器的控制台 提示“XMLHttpRequest cannot load http://www.w3school.com.cn/example/xdom/note.xml. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. Noname1.html:1”
查了一下,大致的意思是 “是ajax跨域,禁止访问”
|
跨域只能使用JSONP来实现,或者通过服务器端获取 http://blog.csdn.net/net_lover/article/details/5172509 http://blog.csdn.net/net_lover/article/details/5172522 |
web三种跨域请求数据方法
Spring 3.1 MVC REST 支持之跨域访问(Cross-origin resource sharing)
jQuery JSONP 实践
XMLHttp小手册,原生ajax参考手册的更多相关文章
- DOM参考手册及事件参考手册
给全局HTML DOM元素增加函数的方法 HTMLElement.prototype.hasClass = function (className) { return new RegExp(" ...
- javascript进击(九)参考手册
完整的 Number 对象参考手册 如需可用于 Number 对象的所有属性和方法的完整参考,请访问我们的 Number 对象参考手册. 该参考手册包含每个属性和方法的描述和实例. 完整的 Strin ...
- Arduino参考手册-函数和变量及电路图
标题: Arduino参考手册-函数和变量及电路图 作者: 梦幻之心星 sky-seeker@qq.com 标签: [#Arduino,#参考手册,#函数,#变量] 目录: [Arduino] 日期: ...
- Lua 5.1 参考手册
Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 云风 译 www.codingno ...
- dubbo 官方参考手册~备案(防止哪天阿里一生气把dubbo给删除了)
首页 || 下载 || 用户指南 || 开发者指南 || 管理员指南 || 培训文档 || 常见问题解答 || 发布记录 || 发展路线 || 社区 E ...
- Lua 5.3 参考手册
转自:http://www.runoob.com/manual/lua53doc/manual.html 1 – 简介 Lua 是一门扩展式程序设计语言,被设计成支持通用过程式编程,并有相关数据描述设 ...
- Spring Security 5.0.x 参考手册 【翻译自官方GIT-2018.06.12】
源码请移步至:https://github.com/aquariuspj/spring-security/tree/translator/docs/manual/src/docs/asciidoc 版 ...
- dubbo协议参考手册(转)
原文链接:http://wely.iteye.com/blog/2331332 协议参考手册 (+) (#) 推荐使用Dubbo协议 性能测试报告各协议的性能情况,请参见:性能测试报告 (+) dub ...
- jQuery 参考手册 - 遍历
jQuery 参考手册 - 遍历 jQuery Ajax jQuery 数据 jQuery 遍历函数 jQuery 遍历函数包括了用于筛选.查找和串联元素的方法. 函数描述 .add()将元素添加到匹 ...
随机推荐
- RPM安装命令总结--转载
原地址:http://www.cnblogs.com/zqwang0929/p/3352237.html 在 Linux 操作系统下,几乎所有的软件均通过RPM 进行安装.卸载及管理等操作.RPM 的 ...
- 【第二课】深入理解Handler
简要讲解Handler是做什么的 我们知道,在Android中,app启动会启动一个进程一个线程——UI线程,UI线程是主线程,并且不允许这个线程阻塞超过5秒,一旦超过5秒就会ANR. 所以较为耗时的 ...
- 手动测试——MTM
在Test Manager中,测试计划用于管理某个迭代的整个测试工作.包括测试用例.测试结果,计划测试的配置. Test Center分为4个主要活动区域: Plan---用于管理整个测试计划,包括计 ...
- sprint3与总结
backlog-看板-燃尽图-每日立会 github:https://github.com/alfredzhu/team-work 总结:这种团队合作的方式很好,大家在一起沟通,相互交流想法,一起解决 ...
- Logger.getLogger和LogFactory.getLog的区别
Logger来自log4j自己的包.如果用Logger.getLogger,需要一个log4j的jar包,用此方式你只能依靠log4j: LogFactory来自common-logging包.如果用 ...
- 【C#】委托
一.委托的基本的写法 internal class Program { private static void Main(string[] args) { ChainDelegate(); Conso ...
- 运用Microsoft.DirectX.DirectSound和Microsoft.DirectX实现简单的录音功能
1.首先要使用Microsoft.DirectX.DirectSound和Microsoft.DirectX这两个dll进行录音,需要先安装microsoft directx 9.0cz这个组件, 百 ...
- csharp:Dapper Sample
You can find Dapper on Google Code here: http://code.google.com/p/dapper-dot-net/ and the GitHub dis ...
- sql 大数据库 插入超时问题解决
解决的办法:1. 不要使用自动收缩, 自动收缩会定期收容数据文件的空闲空间,则处理需要的时候却要扩大数据文件,这两者相反的处理,是冲突的设置方法:ALTER DATABASE MyDataBase S ...
- LeetCode128:Longest Consecutive Sequence
题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequenc ...