jsonp.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="./js/jquery.js"></script>
  9. </head>
  10. <body>
  11. <script>
  12. // $.ajax({
  13. // url: 'http://127.0.0.1:9000/jsonpb',
  14. // dataType: "jsonp",
  15. // jsonp: "successCallback",
  16. // jsonpCallback: 'successCallback',
  17. // success (res) {
  18. // console.log(res)
  19. // }
  20. // });
  21. // function successCallback (data) {
  22. // console.log("更改名称", data)
  23. // }
  24. $(function () {
  25. // post
  26. let url = 'https://ip.taobao.com/outGetIpInfo';
  27. url = "http://127.0.0.1:9000/jsonp";
  28. // cor阻止的
  29. // $.ajax({
  30. // url,
  31. // type: "get",
  32. // success: function (res) {
  33. // console.log(res)
  34. // }
  35. // });
  36. // 跨域的
  37. $.ajax({
  38. url,
  39. type: "get",
  40. dataType: "jsonp", //指定服务器返回的数据类型
  41. // jsonpCallback: "showData",
  42. success: function (res) {
  43. console.log("jsonp的callback: ", res)
  44. }
  45. });
  46. // 跨域的
  47. // $.ajax({
  48. // url: "http://127.0.0.1:9000/jsonpa",
  49. // type: "get",
  50. // dataType: "jsonp", //指定服务器返回的数据类型
  51. // // jsonpCallback: "showData",
  52. // success: function (res) {
  53. // console.log("jsonpa", res)
  54. // }
  55. // });
  56. })
  57. </script>
  58. </body>
  59. </html>