zoukankan      html  css  js  c++  java
  • 夺命雷公狗jquery---61Ajax跨域请求之方法2

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script src="js/jquery.js"></script>
            <script>
                //页面载入事件
                $(function(){
                    //绑定相关的事件
                    $('#btnok').bind('click',function(){
                        //发送ajax
                        $.get('http://www.test.com/ajax.php?fn=?',function(msg){
                            $(msg).each(function(im,item){
                                var id = item.id;
                                var username = item.username;
    
                                $('#result').append(id+'----'+username+'<hr />');
                            });
                        },'jsonp');
    
                    });
                });
            </script>
        </head>
        <body>
            <input type="button" id="btnok" value="获取数据" />
            <hr />
            <div id="result"></div>
        </body>
    </html>

    PHP代码如下:

    <?php
        
        $fn = $_GET['fn'];
    
        //链接数据库(CRM客户关系管理系统接口)
        mysql_connect("localhost",'root','');
        mysql_query('use xsphp');
        mysql_query('set names utf8');
    
        //组装sql语句
        $sql = "select * from admin";
        $res = mysql_query($sql);
        $data = array();
        while($row = mysql_fetch_assoc($res)){
            $data[] = $row;
        }
        $str = json_encode($data);
        echo $fn."($str)";  //这里如果加上单引号就会变成字符串类型,不加单引号他就会变成OBJ类型(也就是一个数组)
  • 相关阅读:
    bzoj1914
    bzoj3144
    bzoj2756
    poj3177
    一些比较水的题目
    bzoj2282
    屯题50AC纪念
    Base64解码中文部分中文乱码的原因
    随机生成36位字符串
    jQuery判断某个元素是否存在某个样式
  • 原文地址:https://www.cnblogs.com/leigood/p/4932988.html
Copyright © 2011-2022 走看看