[英]Access-Control-Allow-Origin' header error in SAPUI5
[英]How to check for No 'Access-Control-Allow-Origin' header error
最好的做法是防止此錯誤發生在最開始。 通過確保服務器將您嘗試從腳本中訪問的域添加到Access-Control-Allow-Origin設置中,您無需在客戶端進行處理。
也就是說,您應該能夠將處理程序附加到XMLHttpRequest對象的錯誤事件。 使用錯誤消息,您可能能夠確定出了什么問題。 但這沒那么有趣。 對客戶端來說,出什么錯並不重要,只是它不會獲取數據,因此您可以相應地進行計划。
var oReq = new XMLHttpRequest();
oReq.addEventListener("error", transferFailed);
oReq.open();
function transferFailed(evt) {
console.log("An error occurred while transferring the file.");
}
詳細信息: https : //developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Asynchronous_request
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.