i am getting error in php while uploading image to databse using jquery, the data in variables arent passing maybe

前端 未结 3 2022
余生分开走
余生分开走 2021-01-20 12:29

My code is a form where it picks a file from the user, then send the data using jQuery to a PHP file where it gets the image content and displays it and in a success functio

3条回答
  •  有刺的猬
    2021-01-20 12:51

    This should work!

    HTML:

    JS:

    $("button").click(function(e) {
    /* prevent default form action */
    e.preventDefault();
    /* get form element */
    var formElement = document.getElementById("my-upload-form");
    /* collect all form data from Form element */
    var formData = new FormData(formElement);
    
    $.ajax({
    url: '/path-to-form-handler.php',
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    method: 'POST',
    success: function(response) {
        console.log(response);
    }
    });
    });
    

    PHP:

    
    

提交回复
热议问题