skip to Main Content

I have this form:

<input type="file" name="CAR_Logo">
<button data-action="save" data-name="Africa">Save</>

How I can update my code to be able to upload the file ?

This is what I have tried:

$('[data-action="save"]').click(function(e) {
e.preventDefault();
CAR_Name = $(this).data('name');
CAR_Logo = $(this).val('CAR_Logo');
});

2

Answers


  1. If you want to upload a file, you first need a web-based programming language that will run in the background. Javascript/Jquery codes are interpreted by users’ computers. What you need is a web server software and related software. For example, it can be php or python django, python flask or ruby on rails.

    Login or Signup to reply.
  2. You can use AJAX

    Your form

    <input id="file" type="file" name="CAR_Logo">
    

    Your script

    $('#form').submit(function(e) {
        e.preventDefault();
        let fd = new FormData(this);
        fd.append('myfile', $('#file').files[0]);
        
    $.ajax({
           url : 'upload.php',
           type : 'POST',
           data : fd,
           processData: false,
           contentType: false,
           success : function(data) {
               console.log(data);
               alert(data);
           }
    });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search