ajax 跨域的小记录

服务器端要返回串中要写上客户端的callback func:

 echo $_GET["jsonpCallback"]. "({\"num\":$num[1]})";


客户端代码:

                $.ajax({

                        url: u,

                        data: {},

                        dataType: 'jsonp',

                        jsonp:'jsonpCallback',   //这个就是json的处理函数名

                        error: function() {

                                console.log("fail");

                        },

                        success:function(res) {

                                console.log(res);

                                $(cell).text(res.num);

                        }

                });


你可能感兴趣的:(ajax 跨域的小记录)