XMLHttp小手册,原生ajax参考手册
2014-10-20 11:20
190 查看
个人做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
上面的代码直接拿来运行是不行的,打开谷歌浏览器的控制台 提示“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跨域,禁止访问”
说说JSON和JSONP
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来实现,或者通过服务器端获取 另外,Access-Control-Allow-Origin 方法可以参考 http://blog.csdn.net/net_lover/article/details/5172509 http://blog.csdn.net/net_lover/article/details/5172522 /article/1692996.html |
web三种跨域请求数据方法
springmvc跨域请求乱码的解决Spring 3.1 MVC REST 支持之跨域访问(Cross-origin resource sharing)
说说JSON和JSONP
jQuery JSONP 实践
相关文章推荐
- xmlhttp ,ajax 参考手册
- xmlhttp ,ajax 参考手册
- jQuery 参考手册 - Ajax
- jQuery 参考手册 - Ajax
- JavaScript原生xmlHttp与jquery的ajax方法json数据格式实例
- jQuery 参考手册 - Ajax
- jQuery 参考手册 - Ajax
- JavaScript原生xmlHttp与jquery的ajax方法json数据格式实例
- jQuery 参考手册 - Ajax
- XmlHttp中文参考手册
- 2016.11.14 jq(参考手册 - CSS 操作 Ajax 数据)
- Ajax 对象 xmlhttp --dojo Quick Start/dojo入门手册2
- jQuery 参考手册 - Ajax
- jQuery 参考手册 - Ajax
- hibernate参考手册之---原生SQL查询
- Jquery和Ajax的使用参考手册
- 原生AJAX调用四步曲:仅供初学者参考
- VIM 参考手册
- linux常用命令参考手册(二)
- 初学AJAX2----HTML格式下原生ajax