Javascript MeteorJS中的“访问控制允许来源”错误
我正在使用Laravel Lumen为我的MeteorJS应用程序创建API。这是我在imports\api\tasks.js上的代码inm y meteorJS 但当我遇到这个错误时:Javascript MeteorJS中的“访问控制允许来源”错误,javascript,api,meteor,meteor-blaze,restful-url,Javascript,Api,Meteor,Meteor Blaze,Restful Url,我正在使用Laravel Lumen为我的MeteorJS应用程序创建API。这是我在imports\api\tasks.js上的代码inm y meteorJS 但当我遇到这个错误时: XMLHttpRequest cannot load http://localhost:8000/api/v1/car. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origi
XMLHttpRequest cannot load http://localhost:8000/api/v1/car. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 405.
tasks.js:81 http post error
有人有主意吗?我是MeteorJS新手在你的服务器/main.js中试试这个
WebApp.rawConnectHandlers.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
return next();
});
有人试图回答,但我不明白。你试试运气。
你把这个方法称为什么?该方法名为tasks.insert,但您提供的代码仅调用fetchDataFromUrl方法 这里有一些想法 检查客户端上的调用是否异步使用。在客户端的Metor HTTP文档中:必须通过传递回调异步使用此函数。请注意,有些浏览器在发送请求之前先发送一个选项请求,以确定CORS头 在我的一个项目中,我也遇到了CORS问题,最终我只使用了HTTP库服务器端。您可以通过使用Meteor.isServer围绕HTTP调用来实现这一点
你在用nginx吗?我在用我的笔记本电脑,我在用XAMPP,windows 10操作系统
WebApp.rawConnectHandlers.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
return next();
});
Try package - simple:json-routes and put following code at serverside startup.
// Enable cross origin requests for all endpoints
JsonRoutes.setResponseHeaders({
"Cache-Control": "no-store",
"Pragma": "no-cache",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With"
});