So I have a simple FormData object with which I am trying to upload a File, without having to do form submit. In HTML I have created a simple form with 1) a File Upload 2) another simple text input for proof of concept. Trying to use the jquery $.post function to achieve this. The PHP file PHP_SIMPLE_AJAX_IMAGE.php just spits back the data from the same sent image. HTML is::
<form id="form_image_upload">
<input type="file" id="input_file" name="input_file_n"></input>
<label for="input_file" id="label_input_file" >choose file</label>
<label for="input_file" id="label_small_input_file">...</label><br>
<input type="text" id='simp_text_id' name='simp_text_n' ><br>
<button id="btn_submit" type="submit" value="submit" class="upload_file">Submit</button>
<form>
<DIV id="Sub_Div_7"> </DIV>
Javascript
$("#input_file").change(function(e){
$("#label_small_input_file").html(e.target.files[0].name);
});
$("#form_image_upload").submit(function(e){
e.preventDefault();
let fd = new FormData(this);
// alert( fd.get('input_file_n').name); //This works
// alert( fd.get('simp_text_n')); //This works
$.post("PHP/PHP_SIMPLE_AJAX_IMAGE.php", fd, function(data){
$("#Sub_Div_7").html(data); });
});
PHP
<?PHP
if(isset($_FILES['input_file_n'])
{ $F_name = $_FILES['input_file_n']['name'];
$F_tmpnm = $_FILES['input_file_n']['tmp_name'];
$F_type = $_FILES['input_file_n']['type'];
$F_size = $_FILES['input_file_n']['size']; }
$text_1 = isset($_POST['simp_text_n']) ? $_POST['simp_text_n'] : "NULL";
echo "Filename: " . $F_name . " Tempname: " . $F_tmpnm . " Type: ". $F_type . " Size: " . $F_size . " TextInput: " . $text_1 ;
?>
When I put the two lines alert( fd.get('input_file_n').name); alert( fd.get('simp_text_n')); I get the alerts with the correct filename, so the fd object is indeed grabbing onto the form data. however when I execute, in the console I get a big error.. something along the lines of: "Uncaught TypeError: Illegal invocation" at the line in the javascript where $.post(... ) is located.. what is wrong?