码迷,mamicode.com
首页 > Web开发 > 详细

使用jsonp来实现跨域请求

时间:2015-04-23 12:49:03      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

<!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 src="jquery-1.9.0.js"></script>
    <script>
        var requestUrl = "http://qxw1192430265.my3w.com/handler.ashx";
        window.onload = function () {
            document.getElementById("btnJq").onclick = function() {
                $.ajax(requestUrl, {
                    type: "get", //请求方式
                    dataType: "jsonp",  //数据发送类型
                    jsonp: "callbackFun",  //服务器端接收的参数
                    jsonpCallback: "fun",  //js处理方法
                    success: function () {
                        alert("成功");
                    }
                });
            }
        }

        function fun(data) {
            for (var key in data) {
                alert(data[key]);
            }
        }
    </script>
</head>
<body>
    <input type="button" id="btnJq" value="Jq按钮" />
</body>
</html>

 

使用jsonp来实现跨域请求

标签:

原文地址:http://www.cnblogs.com/gide/p/4449822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!