本地调用Odoo.sh控制器出现CORS跨域访问问题求助
本地调用Odoo.sh控制器出现CORS跨域访问问题求助
大家好,我现在在本地localhost环境测试时,调用Odoo.sh上的控制器接口一直遇到跨域问题,折腾了好久没解决,想请各位帮忙排查一下。
我的前端请求代码(JavaScript):
try { const response = await fetch(`${BASE_URL}/check_available_venues`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ from_date: start, to_date: end, booking_individuals_total }) }); // Log the full response for debugging console.log('Response status:', response.status); console.log('Response headers:', Object.fromEntries(response.headers.entries())); const responseText = await response.text(); // Get text before potentially parsing as JSON console.log('Response body:', responseText); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}, body: ${responseText}`); } const data = JSON.parse(responseText); // Rest of your existing code... } catch (error) { console.error('Venue check error details:', { message: error.message, stack: error.stack }); this._toastMessage(`Failed to check available venues: ${error.message}`, 'error'); noNextStep = true; }
后端Odoo控制器代码:
@http.route("/check_available_venues", type='json', auth="none", methods=['POST', 'GET'], website=True, csrf=False, cors='*') def check_available_venues(self, from_date, to_date, booking_individuals_total): # 控制器逻辑代码
遇到的错误:
我在浏览器控制台里看到了CORS相关的错误,具体错误截图如下:
错误核心提示是:No 'Access-Control-Allow-Origin' header is present on the requested resource. 但我明明已经在控制器的@http.route里设置了cors='*',还是出现这个问题,实在搞不懂哪里出问题了,麻烦大家帮我看看呀!
备注:内容来源于stack exchange,提问作者Dev Machine
相关产品推荐
相关产品推荐

