AJAX GET方式发送远程请求,chrome开发者工具console中报错:XMLHttpRequest cannot load http://www.shikezhi.com/ajax/getData Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

 

解决办法:使用jsonp格式, ajax请求参数dataType:'JSONP',如:

$.ajax({
   method: "GET",
   url: "http://www.shikezhi.com/ajax/getData",
   dataType: 'JSONP',//加入这个选项即可
   data:params,
   jsonpCallback: "jsonpcallback",
   beforeSend: function (xhr) {
   },
   success: function (response) {
  console.log(response);
   },
   error: function (jqXHR, textStatus, errorThrown) {
   }
});

相关文章:

  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2021-09-27
  • 2022-02-06
  • 2021-08-29
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-12-19
  • 2022-02-18
  • 2022-12-23
相关资源
相似解决方案