-2

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');
});

popomomo
  • 71
  • 4

2 Answers2

0

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);
       }
});
});
POPI
  • 745
  • 6
  • 10
-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.