zoukankan      html  css  js  c++  java
  • jsonp原理与实验

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>jsonp跨域请求</title>
        </head>
        <body>
            <input type="button" onclick="jsonpRequest();" value="跨域请求"/>
            <script>
                tag=null;
                function jsonpRequest(){
                    tag=document.createElement('script');//动态的创建script标签,再添加src属性,src可以实现跨域请求。
                    tag.src="http://..."//list([11,22,33,44]),返回值会调用该函数;
                    document.head.appendChild(tag);
                    
                }
                function list(arg){
                    console.log(arg);
                    document.head.remove(tag);//动态删除标签
                }
            </script>
        </body>
    </html>

    1,jsonp的原理:动态的创建script标签,通过该标签的src属性实现跨域操作。操作完后,会自动的删除刚刚动态创建的标签。

  • 相关阅读:
    sql推断时间
    COCOFrame
    第41周一
    第40周日
    第40周六
    第40周五
    第40周四
    第40周三国庆
    第40周二晚
    第40周二
  • 原文地址:https://www.cnblogs.com/gjx1212/p/13739704.html
Copyright © 2011-2022 走看看