1、創建一個空的html文件test.html,引入jquery2、調用ajax$.ajax({
url: 'http://XXXXXXXXXXXXXX', type: 'post',
success: function() {
console.log('成功');
}, error: function() {
console.log('失敗');
}
});3、url中給出的是項目的接口地址,直接訪問是可以得到數據的4、為何直接在瀏覽器打開test.html就會打印失敗,并提示XMLHttpRequest cannot load *******(接口地址). No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file:
//' is therefore not allowed access.5、這是跨域導致的錯誤嗎?該如何解決?補充:1、后端返回的數據格式是json2、同事給的方案:在tomcat中配cors的filter,添加了相關jar包(cors-filter-2.5,java-property-utils-1.10),不起作用
ajax如何跨域?
慕碼人2483693
2018-10-11 14:11:12