Jquery Ajax发布到Laravel API访问错误

Jquery Ajax发布到Laravel API访问错误,jquery,ajax,Jquery,Ajax,我创建了一个api,它从一个单独的域接收来自表单的帖子。当我用邮递员的时候 标题部分 Content-Type:application/x-www-form-urlencoded X-Requested-With:XMLHttpRequest 当我加入POST值时,它就起作用了。但当我将其添加到生产服务器时 阿贾克斯: 这些是我从上面得到的错误 Access to XMLHttpRequest at 'https://sample/test/t/start' from origin 'http

我创建了一个api,它从一个单独的域接收来自表单的帖子。当我用邮递员的时候 标题部分

Content-Type:application/x-www-form-urlencoded
X-Requested-With:XMLHttpRequest
当我加入POST值时,它就起作用了。但当我将其添加到生产服务器时 阿贾克斯:

这些是我从上面得到的错误

Access to XMLHttpRequest at 'https://sample/test/t/start' from origin 'https://otherdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Access to fetch at 'https://sample/test/t/start' from origin 'https://otherdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

除非更改类型,否则jQuery默认为form encoded。你不必设置它。参考。在
contentType
的可能重复项下,您是否为ajax路由正确设置了csrf?
Access to XMLHttpRequest at 'https://sample/test/t/start' from origin 'https://otherdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Access to fetch at 'https://sample/test/t/start' from origin 'https://otherdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.