jquery实现跨域访问的方法

来源:互联网 发布:怪物猎人ol数据互通 编辑:程序博客网 时间:2024/05/15 23:50

客户端:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript" src="/js/jquery/jquery.js"></script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                url: 'http://(serverip)/test/test.aspx',
                dataType: "jsonp",
                jsonp: "jsonpCallback",

                //jsonpCallback="cbcall";
                success: function (data) {
                    alert(data.message);
                }
            });
        });
    </script>
</body>
</html>


服务端:/test/test.aspx

   protected void Page_Load(object sender, EventArgs e)
    {
        string jsonCallbak = cls_Fun.CStr(Request["jsonpcallback"]);

        string jsondata ="{\"number\":1,\"message\":\"OK\"}";

       response.write(jsonCallbak+"("+jsondata+")");

    }


说明:

     注释行://jsonpCallback="cbcall";可以省略,去掉注释代码更加简洁。


0 0
原创粉丝点击