访问XMLHTTPREQUEST AT AT ORIAND' null' CORS策略已阻止:NO' Access-Control-Allow-Origin'
我面临以下问题
在'http://127.0.0.0.1:5000/predict_home_price'Null'上访问XMLHTTPREQUEST'http://127.0.0.0.0.1:5000/predict_home_price'已被CORS策略阻止:没有'access-control-allow-allow-allow-allow-origin'标题在请求的资源上存在。
function onClickedEstimatePrice() {
console.log("Estimate price button clicked");
var sqft = document.getElementById("uiSqft");
var bhk = getBHKValue();
var bathrooms = getBathValue();
var location = document.getElementById("uiLocations");
var estPrice = document.getElementById("uiEstimatedPrice");
var url = "http://127.0.0.1:5000/predict_home_price"; //Use this if you are NOT using nginx which is first 7 tutorials
//var url = "/api/predict_home_price"; // Use this if you are using nginx. i.e tutorial 8 and onwards
$.post(url, {
total_sqft: parseFloat(sqft.value),
bhk: bhk,
bath: bathrooms,
location: location.value
},
function(data, status) {
console.log(data.estimated_price);
estPrice.innerHTML = "<h2>" + data.estimated_price.toString() + " Lakh</h2>";
console.log(status);
});
}
I am facing following problem
Access to XMLHttpRequest at 'http://127.0.0.1:5000/predict_home_price' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
function onClickedEstimatePrice() {
console.log("Estimate price button clicked");
var sqft = document.getElementById("uiSqft");
var bhk = getBHKValue();
var bathrooms = getBathValue();
var location = document.getElementById("uiLocations");
var estPrice = document.getElementById("uiEstimatedPrice");
var url = "http://127.0.0.1:5000/predict_home_price"; //Use this if you are NOT using nginx which is first 7 tutorials
//var url = "/api/predict_home_price"; // Use this if you are using nginx. i.e tutorial 8 and onwards
$.post(url, {
total_sqft: parseFloat(sqft.value),
bhk: bhk,
bath: bathrooms,
location: location.value
},
function(data, status) {
console.log(data.estimated_price);
estPrice.innerHTML = "<h2>" + data.estimated_price.toString() + " Lakh</h2>";
console.log(status);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是自我解释的……问题是重复的(我认为不是唯一的)。
no'' 资源出现了允许 - 奥林的标题 - 试图从REST API获取数据时
请求的 cors“ rel =“ nofollow noreferrer”> https://developer.mozilla.org/en-us/docs/web/http/cors
https://develoverer.mozilla.org/en-us/docs/web/security/same-origin_policy
The error is rather self explanatory... and the question is a duplicate (not the only one, I think).
No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy