如何在Javascript中检测XMLHttpRequest()的跨源(CORS)网络错误与其他错误

时间:2014-10-13 22:02:30

标签: javascript jquery xmlhttprequest cors

我想检测此错误

XMLHttpRequest cannot load https://accounts.example.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. 

例如:

$.ajax({
  url: "http://api.jquery.com/jquery.ajax/"
}).done(function() {
  alert( "done" );
});

0 个答案:

没有答案