zoukankan      html  css  js  c++  java
  • jsonp详细原理之一

    /*script标签是不存在跨域请求的,类似的还有img,background:url,link

     你可以想象一下,平时的这些标签都是可以直接引入外部资源的,所以是不存在跨域问题的*/

    function getData(res){
    console.log(res.data);
    }
    /*这里创建一个JS标签,相当于把data.js里面的内容放在当前页面进行执行,这里的data.js里面只要是js执行文件,都可以加载进来进行执行。你也可以把data.js变为一个data.txt,只要里面是正确的js文件书写格式都行。这是最基本的jsonp执行原理*/
    var script=document.createElement('script');
    script.src="data.js";
    document.body.appendChild(script);
    /*data.js内容
    getData({data:'hello world'});
    */
    /*以上内容替换为:如下*/
    /*function getData(res){
    console.log(res.data);
    }
    getData({data:'hello world'});*/

  • 相关阅读:
    poj 1850/poj 1496
    poj 1035
    poj 3252
    hdoj 1013
    poj 2965
    poj 1844
    poj 2309
    蓝桥杯比赛回来后计划。。。
    山大实训第二周感想
    hadoop——Map/Reduce中combiner的使用
  • 原文地址:https://www.cnblogs.com/qiqi105/p/8365173.html
Copyright © 2011-2022 走看看