zoukankan      html  css  js  c++  java
  • 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);
            }
          }
    

  • 相关阅读:
    pandas去重方法
    原生表单组件
    html表单
    html表格基本标签
    文档和网站架构
    文本格式
    【Leetcode链表】奇偶链表(328)
    【Leetcode链表】移除链表元素(203)
    【Leetcode链表】旋转链表(61)
    【Leetcode链表】反转链表 II(92)
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1744889.html
Copyright © 2011-2022 走看看