function getXHR(){
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}else{
try{
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}catch(e1){
try{
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}catch(e2){
throw new Error("xmt is not support!");
}
}
}
} function XHR(){
this.xhr=getXHR();
}
XHR.prototype.getJsonByGet=function(url){
var XHRequest=this.xhr;
XHRequest.open("GET",url);
XHRequest.onreadystatechange=function(){
if(XHRequest.readyState===4 && XHRequest.status===200){
var type=XHRequest.getResponseHead("Content-Type");
if(type.match(/^text/))
return JSON.parse(XHRequest.responseText);
}
}
XHRequest.send(null);
}
XHR.prototype.getJsonByPost=function(url,postJson){
var XHRequest=this.xhr;
XHRequest.open("POST",url);
XHRequest.setRequestHeader("Content-Type","text/plain;charset=UTF-8");
XHRequest.onreadystatechange=function(){
if(XHRequest.readyState===4 && XHRequest.status===200){
var type=XHRequest.getResponseHead("Content-Type");
if(type.match(/^text/))
return JSON.parse(XHRequest.responseText);
}
}
XHRequest.send(JSON.stringify(postJson));
}

  

最新文章

  1. Scalaz(23)- 泛函数据结构: Zipper-游标定位
  2. Windows Phone 版 Cocos2d-x 程序的结构
  3. k近邻法的C++实现:kd树
  4. 动态缓存技术之CSI,SSI,ESI
  5. C++内存分配和拷贝构造函数写研究
  6. 使用Microsoft.ExceptionMessageBox.dll捕获WinForm程序中异常信息并弹窗显示
  7. 设计一个神经网络记住Or运算(日志一)
  8. 深入理解HashMap的扩容机制
  9. python中lambda的使用
  10. 基于Gitlab统计代码行--统计所有仓库、所有提交人的代码总行数(新增加-删除)
  11. L1范式和L2范式
  12. 回文(palindrome)
  13. linux文件名称查找which,whereis,locate
  14. Django基础必备三神装(HttpResponse、render,、redirect)
  15. mysql好用的函数
  16. windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹
  17. HDU 5186 zhx's submissions (进制转换)
  18. 编写高质量代码改善C#程序的157个建议——建议71:区分异步和多线程应用场景
  19. Oracle中对现有表增加列
  20. bzoj 3612 [Heoi2014]平衡——整数划分(dp)

热门文章

  1. Storm官方文档翻译之创建Storm项目
  2. ORACLE里锁有以下几种模式,v$locked_object,locked_mode【转】
  3. 好题 线段树对数据的保存+离线的逆向插入 POJ 2887
  4. byte数组如何转为short数组 (转)
  5. android全屏和取消全屏 旋转屏幕
  6. HttpCookie类
  7. 巧妙使用Contains()方法查找一个数是否在某堆数中
  8. linux视频学习3(shell和网络)
  9. XListview的下拉刷新、上拉加载、用Pull解析XML
  10. hdu 1001 二叉树搜索