-2

how can i upload an image using jQuery so it wont have to refresh the page? so i can use the uploaded image. i have no idea how to submit a file through jQuery :/

if i have the following form

<form action = "myCurrentPage" method = "POST" enctype = "multipart/form-data">
    <input type = "file" name = "LogoImage" id = "LogoImage">
</form>

1 Answers1

0

HTML:

<form id='myForm' onsubmit='doUpload()' action = "javascript:void(0)" method = "POST" enctype = "multipart/form-data">
    <input type = "file" name = "LogoImage" id = "LogoImage">
</form>

Javascript:

function doUpload() {


var formData = new FormData(document.getElementById("myForm"));


$.ajax({
   url:            "/admin/scripts/addpet.php",
   dataType:       "xml",
   type:           "POST",
   processData:    false,
   contentType:    false,
   data:           formData
}).done(function(xmlDoc) {
});

}

On your php side you grab the file like you normally would. $_FILES['fileName']['tmp_name']

Null
  • 61
  • 5