AJAX file upload in laravel

后端 未结 3 1882
臣服心动
臣服心动 2020-12-03 13:24

I\'ve been trying to get ajax file upload working in lavavel 4 since last two days and I\'m soo out of luck right now.

my jquery block

$(document).r         


        
3条回答
  •  北海茫月
    2020-12-03 13:35

    The key are in your ajax request. In the controller you can do whatever you want.

    var form = document.forms.namedItem("yourformname"); // high importance!, here you need change "yourformname" with the name of your form
    var formdata = new FormData(form); // high importance!
    
    $.ajax({
        async: true,
        type: "POST",
        dataType: "json", // or html if you want...
        contentType: false, // high importance!
        url: '{{ action('yourController@postMethod') }}', // you need change it.
        data: formdata, // high importance!
        processData: false, // high importance!
        success: function (data) {
    
            //do thing with data....
    
        },
        timeout: 10000
    });
    

提交回复
热议问题