Gabriel Alejandro
Gabriel Alejandro

Reputation: 225

Laravel 5: The server responded with a status of 405 (Method Not Allowed)

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

Answers (1)

eray
eray

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

Related Questions