[英]Laravel 405 Method Not Allowed calling POST method via GET
Whenever I am trying to make an ajax call with base64 image in body it gives error as:每当我尝试在 body 中使用 base64 图像进行 ajax 调用时,它都会给出以下错误:
The GET method is not supported for this route.此路由不支持 GET 方法。 Supported methods: POST.
支持的方法:POST。
Here is my ajax call:这是我的ajax调用:
async function addToCart() {
document.getElementById('preloader').style.display = 'block';
document.getElementById('addToCartButton').style.display = 'none';
// Get base64URL
var image = "";
var full_image = "";
if (document.getElementById("category_id").value == 'customize back cover') {
//console.log("652")
await html2canvas(document.getElementById("html-content-holder")).then(function (canvas) {
document.body.appendChild(canvas);
var base64URL = canvas.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');
full_image = base64URL;
image = document.getElementById('selectedImage').src;
});
}
$.ajax({
type: "POST",
url: "http://emlt.thebakeologyindia.com/add_to_cart", // You add the id of the post and the update datetime to the url as well
data: {
_token: document.getElementById('token').value,
user_id: document.getElementById('user_id').value,
product_id: document.getElementById('product').value,
quantity: document.getElementById('quantity').value,
image: image,
full_image: full_image
},
success: function (response) {
// If not false, update the post
//console.log(response);
swal({
title: response.data.status,
text: response.data.message,
icon: response.data.status,
});
if(response.data.status == "error")
{
document.getElementById('addToCartButton').style.display = 'block';
document.getElementById('preloader').style.display = 'none';
}
else
{
document.getElementById('itemInCartLink').style.display = 'block';
document.getElementById('addToCartButton').style.display = 'none';
document.getElementById('preloader').style.display = 'none';
}
},
error: function (error) {
document.getElementById('addToCartButton').style.display = 'block';
document.getElementById('preloader').style.display = 'none';
swal({
title: "Error",
text: error.message,
icon: "error",
});
}
});
}
Here is the form data example:这是表单数据示例:
_token: RHJrQ4wX6XbXqi0wOx8sMiFHCuXVI2HclGB3rDco, user_id: 1, product_id: 1, quantity: 1, image: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu8AAAH0CAYAAACNesOUAAAgAElEQVR4XoS9iZLjWnIsGMRCAlxy.........., full_image: data:image/octet-stream;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBg..........,
If I remove the images then it works fine.如果我删除图像,那么它工作正常。 And it also works perfectly in localhost.
它也可以在本地主机中完美运行。 This issue occurs in server only.
此问题仅发生在服务器中。 Here is the link of the website: http://emlt.thebakeologyindia.com/details/1 .
这是网站的链接: http : //emlt.thebakeologyindia.com/details/1 。 You can add any other product it will work fine but when you will try to add customize back cover products then this issue occurs because then only I am sending the images.
您可以添加任何其他产品,它会正常工作,但是当您尝试添加自定义封底产品时,就会出现此问题,因为只有我发送图像。 I am not able to figure out what the problem is.
我无法弄清楚问题是什么。
Here is the complete error log:这是完整的错误日志:
{
"message": "The GET method is not supported for this route. Supported methods: POST.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException",
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 256,
"trace": [
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 242,
"function": "methodNotAllowed",
"class": "Illuminate\\Routing\\RouteCollection",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 176,
"function": "getRouteForMethods",
"class": "Illuminate\\Routing\\RouteCollection",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 634,
"function": "match",
"class": "Illuminate\\Routing\\RouteCollection",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 623,
"function": "findRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 612,
"function": "dispatchToRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 176,
"function": "dispatch",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"function": "Illuminate\\Foundation\\Http\\{closure}",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line": 27,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line": 62,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/fideloper/proxy/src/TrustProxies.php",
"line": 57,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Fideloper\\Proxy\\TrustProxies",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 151,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/thebvcgn/MobileCoverEcom/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 116,
"function": "sendRequestThroughRouter",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/home/thebvcgn/emlt.site/index.php",
"line": 55,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
}
]
}
Your route specifies POST method.您的路线指定POST方法。
But you hitting the method via a GET method.但是您通过GET方法点击该方法。
Either correct the method call to POST, or make the route accept both GET and POST要么更正对 POST 的方法调用,要么让路由同时接受 GET 和 POST
Route::match(['get', 'post'], '/action', 'ExampleController@action');
It is definitely due to the server configuration.这肯定是由于服务器配置。 Try hosting it in different environment, it will work.
尝试在不同的环境中托管它,它会起作用。 I too have faced this issue and I think its due to upload image size php configuration in the server.
我也遇到过这个问题,我认为这是由于在服务器中上传图像大小的 php 配置。
The error states a problem with the route.该错误表明路由存在问题。 It indicates that you configured the route to work with get and head verbs yet are using post in the ajax call.
它表明您配置了使用 get 和 head 动词的路由,但在 ajax 调用中使用了 post。
please run: php artisan route:list
to check if the route you're using in the ajax call is loaded.请运行:
php artisan route:list
以检查您在 ajax 调用中使用的路由是否已加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.