JS跨域问题

JS跨域问题

参考资料

关于跨域:http://www.cnblogs.com/chenshishuo/p/4919224.html

关于JS跨域Ajax+PHP服务端解决方案:http://www.itnose.net/detail/483850.html

动动手----->Ajax+python服务端

将『 关于JS跨域Ajax+PHP服务端解决方案:http://www.itnose.net/detail/483850.html 』改成ajax方案

  • Ajax
        $.ajax({
            type: "get",
            async: false,
            url: "http://127.0.0.1:8000/ok",
            dataType: "jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
            jsonpCallback:"flightHandler",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据
            success: function(json){
                console.log(json['name']);
            },
            error: function(){
                alert('fail');
            }
        });
  • python(比较无耻)
return 'flightHandler({"name":"Zjmainstay","age":23})'

注意: Ajax的jsonpCallback名称要与服务端返回的名称要对应,例如上述的flightHandler

posted @ 2017-06-27 20:50  考拉小无  阅读(153)  评论(0编辑  收藏  举报