此问题通常发生在尝试通过本地文件系统(file://)访问单个 HTML 页面并从 localhost 进行 AJAX 请求时。这是由于浏览器的同源策略所引起的。为了解决这个问题,你可以使用一个本地服务器来模拟 localhost:
$.ajax({ url: "http://localhost:8080/some/file", type: "GET", success: function (response) { console.log(response); }, error: function (xhr, status, error) { console.log(status, error); } });