[英]CORS Error:Response to preflight request doesn't pass access control check when trying to access Azure Search Api
我正在使用ajax put請求執行合並操作,以為天藍色搜索索引中的特定文檔更新名為DocType的字段。 但是收到錯誤:無法加載資源:服務器以狀態404(未找到)響應對預檢請求的響應未通過訪問控制檢查:請求中不存在“ Access-Control-Allow-Origin”標頭資源
我正在執行的ajax請求:
var jsonMeta = {
"value": [
{
"@search.action": "merge",
"metadata_storage_path": "*******jkio********",
"DocType": "Test_Merge"
}
]
};
var jsonString = JSON.stringify(jsonMeta);
var url = "https://documentsmartdetect.search.windows.net/indexes/document-smartdetect-index/docs/index?api-version=2017-11-11";
$.ajax({
url: url,
method: 'PUT',
data: JSON.stringify(jsonMeta),
// This is the important part
xhrFields: {
withCredentials: true
},
crossDomain: true,
contentType: 'application/json',
headers: {
"api-key": "***************89**",
},
success: function (response) {
},
error: function (xhr, status) {
alert('error');
}
});
我也嘗試過使用Allowed origin type:全部在azure門戶上。 需要一些協助來解決CORS問題。
Azure搜索不允許從前端JavaScript進行調用,因此無法直接執行所需的操作。 您將必須從后端調用Azure搜索。
實際上,這也是一個嚴重的安全問題,因為您的搜索鍵現在在發送給Web應用程序所有訪問者的JavaScript中是公開的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.