每当我尝试在主体中使用base64图像进行Ajax调用时,都会显示错误消息:
此路由不支持GET方法。支持的方法:POST。
这是我的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",
});
}
});
}
这是表单数据示例:
_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..........,
如果我删除图像,则可以正常工作。而且它在localhost中也可以完美运行。仅在服务器中会发生此问题。 这是网站的链接:http://emlt.thebakeologyindia.com/details/1。您可以添加任何其他产品,都可以正常工作,但是当您尝试添加自定义封底产品时,就会出现此问题,因为只有我在发送图像。我无法弄清楚问题出在哪里。
这是完整的错误日志:
{
"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": "->"
}
]
}
答案 0 :(得分:1)
这肯定是由于服务器配置。尝试将其托管在其他环境中,它将起作用。我也曾经遇到过这个问题,我认为这是由于服务器中上传的图片大小为php配置造成的。
答案 1 :(得分:0)
该错误指出路线存在问题。这表明您已配置路线以使用get和head动词,但仍在ajax调用中使用post。
请运行:
php artisan route:list
检查您在ajax调用中使用的路由是否已加载。
答案 2 :(得分:0)
您的路线指定了 POST 方法。
但是您通过 GET 方法点击了该方法。
将方法调用更正为POST,或者使路由接受GET和POST
Route::match(['get', 'post'], '/action', 'ExampleController@action');