• XMLHttpRequest Level 2的简单例子


    首先根据后面给出的网址对目标网站做一些设置,让它充许跨域访问:mozillaw3cmsdn

    新设计出来的跨域方案是极其优秀的,IE8是XDomainRequest,Firefox3.5、Safari4、Chrome 2等是沿用原来的XMLHttpRequest对象,它们都拥有一些相同的方法处理各种回调:

    • onload :请求成功时调用。
    • onerror:请求失败时调用。
    • onabort:请求中断时调用(使用abort方法)

    因此这跨域请求是非常简单了!

          if("1"[0]){//只允许IE8与较新的标准浏览器进入下面逻辑
            var xhr=window.XDomainRequest?new XDomainRequest:new XMLHttpRequest;
            try{
              xhr.onload=function(){
                //由于返回的JSON过长,我们在演示时把它截短一些
                alert([xhr.responseText.slice(0,1000),xhr]);
              };
              xhr.open("GET","http://ss-o.net/json/wedataAutoPagerize.json");
              xhr.send();
            }catch(e){
              alert("请求失败: "+e.message);
            }
          }
    

  • 相关阅读:
    PythonStudy——数据类型总结 Data type summary
    PythonStudy——可变与不可变 Variable and immutable
    PythonStudy——列表操作 List operatio
    PythonStudy——列表的常用操作 List of common operations
    PythonStudy——列表类型 List type
    PythonStudy——字符串扩展方法 String extension method
    PythonStudy——字符串重要方法 String important method
    AWT,Swing,RCP 开发
    JQuery插件机制
    最新知识网站
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1744889.html
Copyright © 2020-2023  润新知