Good programmers web front end shared learning route status codes ajax.status AJAX and packaging, AJAX Status Code Description
1 **: Request received, continuing process
2 **: operating successfully received, analyzed, accepted
** 3: complete the request must be further processed
4 **: a request contains bad syntax or can not be completed
5 **: a server performs perfectly valid request failed
100-- customers must continue to make requests
101-- client asks the server to convert the HTTP protocol version upon request
200-- trading success
201-- prompted know the new URL file
202-- accept and deal with, but the process is not completed
203-- return uncertain or incomplete information
204-- requests received, but returned information is null
205-- server completes the request, the user agent must reset the current document has been visited
206-- server has completed GET request some users
300-- resource request may be obtained in many
301-- deletion request data
302-- address found in other requested data
303-- advise clients to access the URL or other access methods
304-- client has performed a GET, but the file does not change
305-- resources must be requested from the server specified address
306-- HTTP previous version of code used in the current version is no longer in use
307-- stated delete temporary resource request
400-- Bad Request, such as syntax errors
401-- request authorization failed
402-- effective retention head in response ChargeTo
403-- request is not allowed
404-- not find the file, query or URl
405-- method does not allow the user fields defined in Request-Line
406-- according to Accept sent by the user to drag, the requested resource is not accessible
407-- similar 401, the user must first be authorized on the proxy server
408-- client request is not completed within a user-specified time hungry
409-- on the current status of the resource, the request can not be completed
410-- no longer have this resource on the server and no further reference address
411-- server denies the user-defined attribute request Content-Length
412-- request one or more header fields in the current request error
413-- resource request is larger than the size allowed by the server
414-- resources requested URL is longer than the length allowed by the server
415-- requested resource request is not supported project format
416——请求中包含Range请求头字段,在当前请求资源范围内没有range指示值,请求也不包含If-Range请求头字段
417——服务器不满足请求Expect头字段指定的期望值,如果是代理服务器,可能是下一级服务器不能满足请求
500——服务器产生内部错误
501——服务器不支持请求的函数
502——服务器暂时不可用,有时是为了防止发生系统过载
503——服务器过载或暂停维修
504——关口过载,服务器使用另一个关口或服务来响应用户,等待时间设定值较长
505——服务器不支持或拒绝支请求头中指定的HTTP版本
学过状态码之后我们可以做一些事情:
1.var AJAX=new XMHttprequert( );
//拨号:设置请求参数;
2.AJAX.open('get','data/test.json',true);
3. ajax.onreadystatechange = function()
{
if (ajax.readyState == 4 && ajax.status == 200)
{
func_succ(ajax.responseText);
}
else
{
//alert("ajax faild readyState:"+ajax.readyState+" status:"+ajax.status);
}
};
4.ajax.send(null);
AJAX的兼容问题及封装;
function InitAjax(){
var ajax=false;
try{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E){
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined'){
ajax = new XMLHttpRequest();
}
return ajax;
}
function DoAjaxGet(ajax, url, func_succ){
ajax.open("GET", url, true);
ajax.onreadystatechange = function(){
if (ajax.readyState == 4 && ajax.status == 200){
func_succ(ajax.responseText);
}else{
//alert("ajax faild readyState:"+ajax.readyState+" status:"+ajax.status);
}
};
ajax.send(null);
}
function DoAjaxPost(ajax, url, func_succ, post_datas){
ajax.open("POST", url, true);
ajax.onreadystatechange = function(){
if (ajax.readyState == 4 && ajax.status == 200){
func_succ(ajax.responseText);
}else{
alert('ajax faild readyState:'+ajax.readyState+" status:"+ajax.status);
}
};
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(post_datas);
}
ajax缓存问题:用时间戳清除缓存;
DoAjaxGet(ajax,'data/test.txt?t='+ new Date().getTime(),aaa)