I have the following files. Nothing is displayed in the Response header of developer tools. I am expecting the variables related to files and post in my accept.php
page.
- send.php
<?php
echo '
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="file.js"></script>
<form id="data">
<input type="hidden" name="id" value="123" readonly="readonly">
User Name: <input type="text" name="username" value=""><br />
Profile Image: <input name="profileImg[]" type="file" /><br />
Display Image: <input name="displayImg[]" type="file" /><br />
<button type = "button" onclick="submitFileTest()">Submit Button </button>
</form>
';
?>
- file.js
function submitFileTest() {
//grab all form data
var formData = new FormData($(this)[0]);
console.log("Form Data Test");
console.log(formData);
$.ajax({
url: 'accept.php',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
//alert(returndata);
console.log(returndata);
}
});
}
<?php
if (isset($_POST['id'])) {
$id = $_POST['id'];
var_dump($id);
echo $id;
}
if (isset($_POST['username'])) {
$username = $_POST['username'];
var_dump($username);
echo $username;
}
if (isset($_FILES['profileImg'])) {
$profileImg = $_FILES['profileImg'];
var_dump($profileImg);
echo $profileImg;
}
if (isset($_FILES['displayImg'])) {
$displayImg = $_FILES['displayImg'];
var_dump($displaying);
echo $displayImg;
}
?>