zoukankan      html  css  js  c++  java
  • 浅论ajax跨域!从一个例子开始!

    
    

    //所谓跨域,根据同源策略缘故

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <button id="button" name="button" onclick="jsonp()">button</button>
        <div id="div1"></div>
    </body>
    <script>
        function jsonp(){
    
                var s1=document.createElement("script");
    
                s1.src="2.php?cb=show";
    
                document.body.appendChild(s1);   
    
            }
    
    
            var dd=document.getElementById("div1");
    
            function show(data){
    
                dd.innerHTML=data.name;
    
            }
    </script>
    </html>

    php文件如下,此时通过参数cb来了接的,这样就是是

    <?php  
    
    $show=$_GET['cb'];
    $xjson="{'name':'user1'}";
    
    echo $show."(".$xjson.")";
    ?>
  • 相关阅读:
    bzoj 3924
    bzoj 1095
    luogu 4886
    bzoj 2152
    CF960G
    bzoj 3561
    bzoj 4176
    bzoj 4407
    bzoj 3309
    luogu 4608
  • 原文地址:https://www.cnblogs.com/null11/p/4798826.html
Copyright © 2011-2022 走看看