如何解决Laravel Ajax不起作用,此路由不支持GET方法支持的方法:POST
我尝试用Laravel测试Ajax。 我写了可以在php中工作的测试代码,但是我无法将其移至Laravel。
我的脚本:
function refresh() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200)
{
document.getElementById("refresh").innerHTML = this.responseText;
if (this.responseText=="refresh")
{
location.reload();
}
}
};
xmlhttp.open("POST",'refresh',true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("X-CSRF-TOKEN",document.querySelector('meta[name="csrf token"]').content );
xmlhttp.send(refresh);
我的路线:
Route::post('refresh',[ZamowieniaController::class,'ajax']);
在我的控制器中:
public function ajax(Request $request)
{
return test;
}
我收到错误消息:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。