I'm trying to send a file to a php script through ajax, however I see that it's not being passed properly as I tried to echo that file and got a null
response. How can I solve this?
HTML JS code
<script type="text/javascript">
$(function(){
$("#first").submit(function(event){
event.preventDefault();
$(this).find(".error").remove();
file = $(this).find("input[name=file_save]").val();
form = $(this);
url = $(this).attr("action");
$.post(url,{file_save:file}, function(data){
console.log(data);
},"json");
return false;
});
});
</script>
Php script (addImages.php)
<?php
$username = $_POST['files'];
$tableau["error"] = $username;
echo json_encode($tableau);
?>