原生XHR:
function submitJsonp2() { var tag = $(‘<script>‘); tag.attr(‘src‘, ‘http://127.0.0.1:8000/an/?callback=fuck‘);//发送给别的服务器自己的回调函数名 $(document.head).append(tag); $(document.head).children(tag).remove(); }
在页面用ajax跨域:
function fuck(arg) {//定义回调函数 $(‘#content‘).empty().append(arg); } function submitJsonp3() { $.ajax({ url: ‘http://127.0.0.1:8000/an/‘, type: "GET", dataType: ‘jsonp‘, jsonp:‘callback‘, jsonpCallback:‘fuck‘//指定回调函数 }) }
原文:https://www.cnblogs.com/Neroi/p/10476329.html