Skip to content Skip to sidebar Skip to footer

Can't Send File With Ajax To Php File

I am having a problem with receiving File Data. This is my HTML FORM: As you can see it sends us to the file General.js and the php page that need to recieve this: $fileName = $_

Solution 1:

Try using this...

    $(document).ready(function (e) {
    $("#Form").on('submit',(function(e) {
        e.preventDefault();
        $.ajax({
            url: "uploader.php", // Url to which the request is sendtype: "POST",             // Type of request to be send, called as methoddata: newFormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)contentType: false,       // The content type used when sending data to the server.cache: false,             // To unable request pages to be cachedprocessData:false,        // To send DOMDocument or non processed data file it is set to falsesuccess: function(data)   // A function to be called if request succeeds
            {
                 console.log(data);
            }
        });
    }));
});

Solution 2:

change

var formData = newFormData(document.getElementById('Form'));

to

var fd = new FormData();     
   fd.append("userfile", document.getElementById('userfile').value);

Post a Comment for "Can't Send File With Ajax To Php File"