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

js执行跨域请求

时间:2016-04-04 16:12:28      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

   //js执行跨域请求
        var _script = document.createElement(‘script‘);
        _script.type = "text/javascript";
        _script.src = "http://api.map.baidu.com/location/ip?ak=Z90WfgUtDDPnr2pfG4yIbkwLEmyoeetx&callback=f";
        document.head.appendChild(_script);

        function f(data){
            alert(data.content.point.y);
        }

浏览器不会阻止script标签的跨域请求

因此在这里动态添加一个script标签

关键的地方是在链接中对应的callback参数的添加,其中callback=f中的f就是即将执行的回掉函数,其中f(data)中的参数data是执行跨域请求后返回的结果,在页面中的回掉函数中对返回结果进行处理

js执行跨域请求

标签:

原文地址:http://www.cnblogs.com/itboy-2009/p/5352043.html

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