个人做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跨域,禁止访问”
springmvc跨域请求乱码的解决
说说JSON和JSONP
开始做,坚持做,重复做