Reputation: 225
I am trying to upload a file via ajax, but it throws this message: "The server responded with a status of 405 (Method Not Allowed)" The route is defined like this: Route::post('/file/upload', 'Upload@importFile');
And the Ajax code I'm using is this:
var upload_file=function(input_file,format){
var formData = new FormData();
formData.append("upload_file",input_file);
// formData.append("format",format);
return $.ajax({
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
data: formData,
cache:false,
url: '/file/upload/'
});
}
Somehow it works locally, but it throws this error when I try it on the server, however I've used this same code before and it's worked fine
Upvotes: 1
Views: 6215
Reputation: 81
You can try to remove last "/" in the url.Like that: url: '/file/upload'
var upload_file=function(input_file,format){
var formData = new FormData();
formData.append("upload_file",input_file);
// formData.append("format",format);
return $.ajax({
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
data: formData,
cache:false,
url: '/file/upload'
});
}
Upvotes: 1