0

the ajax call for posting an image :

function FileUploadCheck() {
var formData = new FormData();
formData.append('LogoImageUploader', jQuery('#LogoImageUploader')[0].files[0]);

  jQuery.ajax({
          type: "POST",       
          url: "FileUploadChecker.php",
          contentType: "multipart/form-data",         
          data: formData,
          processData: false, 
          contentType: false,
          success : function(result){
              alert(result);

          }
        });
}

i assume the image is getting posted successfully request payload for the post request

at the php script end :

<?php

echo var_dump($_FILES); 

?>

All of the above code works fine for me when i make use of jquery 1.7.2 but I can not keep using the jquery as other JS libraries existent in application as incompatible with the jquery 1.7.2 . I need to know if i could only import any standalone JS (maybe which provides ajax functionality) to make this work similar to jquery 1.7.2.

Sagar V
  • 12,158
  • 7
  • 41
  • 68

1 Answers1

0

I found an answer to this :

function FileUploadCheck() {
var formData = new FormData();
formData.append('LogoImageUploader', jQuery('#LogoImageUploader')[0].files[0]);

    var http = new XMLHttpRequest();
    var url = "FileUploadChecker.php";

    http.open("POST", url, true);

    //when i uncommentated this line, the upload failed, as i tried to manually set the header to the post, but i let XHR to set the header automatically this works.   
    //http.setRequestHeader("Content-type", "multipart/form-data");



    http.onreadystatechange = function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
        }
    }
    http.send(formData);
}