1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jsonp的JQuery封装解决ajax跨域问题</title> </head> <body> <script type="text/javascript" src="/a/js/Jquery.js"></script> <script type="text/javascript"> function sayHello(data){ $("#mydiv").html(data.username); } $(function(){ $("#btn").click(function (){ $.ajax({ type:"GET", url:"http://localhost:8081/b/jsonp3", dataType:"jsonp", jsonp:"fun", jsonpCallback:"sayHello", }) }) }) </script> <button id="btn">jsonp的JQuery封装解决ajax跨域问题</button> <div id="mydiv"></div> </body> </html>
|