http://www.cnblogs.com/rubylouvre/archive/2013/01/08/2851051.html

  

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>
		Ajax = function(){
		    function request(url,opt){
		        function fn(){}
		        var async   = opt.async !== false,
		            method  = opt.method    || 'GET',
		            data    = opt.data      || null,
		            success = opt.success   || fn,
		            failure = opt.failure   || fn;
		            method  = method.toUpperCase();
		        if(method == 'GET' && data){
		            url += (url.indexOf('?') == -1 ? '?' : '&') + data;
		            data = null;
		        }
		        var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
		        xhr.onreadystatechange = function(){
		            _onStateChange(xhr,success,failure);
		        };
		        xhr.open(method,url,async);
		        if(method == 'POST'){
		            xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;');
		        }
		        xhr.send(data);
		        return xhr;
		    }
		    function _onStateChange(xhr,success,failure){
		        if(xhr.readyState == 4){
		            var s = xhr.status;
		            if(s>= 200 && s < 300){
		                success(xhr);
		            }else{
		                failure(xhr);
		            }
		        }else{}
		    }
		    return {request:request};
		}();

		console.log(Ajax.request("http://baidu.com",{method:"POST"}));
	</script>
</body>
</html>

  

最新文章

  1. Zabbix自定义监控8080端口的连接数
  2. Java基础——继承、接口
  3. &lt;s:property value=&quot;&quot;/&gt; 怎么截取返回值的固定长度的字符串
  4. gpio高阻态
  5. idea 小技巧
  6. mysql在Linux下
  7. @weakify, @strongify ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
  8. WeakReference(弱引用)
  9. rubycas-client单点登录
  10. MVC 中的 ViewModel
  11. 采访ServiceStack的项目领导Demis Bellot——第2部分(转)
  12. No valid host was found. There are not enough hosts available
  13. HDU 4927 大数运算
  14. [收藏转贴]struct探索&#183;extern &quot;C&quot;含义探索 &#183;C++与C的混合编程&#183;C 语言高效编程的几招
  15. NoSql中的B-tree、B+tree和LSM-tree
  16. MFC中SDI程序创建流程的回顾
  17. BOM简单知识
  18. 汲取营养的blog专栏
  19. Python之函数第三篇
  20. RabbitMQ(3) Spring boot集成RabbitMQ

热门文章

  1. CAD二次开发(02)-添加对象到模型空间
  2. Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
  3. dll签名两种方法
  4. 解决The hierarchy of the type is inconsistent错误
  5. 部署zookeeper实践
  6. MyEclipse常见错误汇总,中英注释版(长期更新)
  7. bzoj1005: [HNOI2008]明明的烦恼(prufer+高精度)
  8. Fast Flux技术——本质就是跳板,控制多个机器,同一域名指向极多的IP(TTL修改为0),以逃避追踪
  9. hdoj--2282--Chocolate(最小费用)
  10. Lamp安装 php-v5.6【ZendGuardLoader】的问题