I would like to send my php variables and input file by AJAX with something like this ..
$(document).ready(function(){
$("#submit").click(function(){
//var formData = new FormData($('form#data')[0]);
var chaID = "<?php echo $chaID; ?>";
var row_number = "<?php echo $row_number; ?>";
var tag = "<?php echo $tag; ?>";
var data = '&chaID=' + chaID + '&row_number=' + row_number + '&tag=' + tag;
//Returns successful data submission message when the entered information is stored in database.
$.ajax({
type: "POST",
url: "ajax_challenge.php",
data : data,
cache: false,
success: function(result){
$('#level').modal('show');
},
contentType: false,
processData: false
});
return false;
});
});
My formData is working fine so let's focus on var data. When I run this function the ajax_challenge.php response "undefined index" but in request part it shown &chaID=7&row_number=2&tag=6 so it should work.
Maybe I did something wrong with php?
$chaID = $_POST['chaID'];
$row_number = $_POST['row_number'];
$tag = $_POST['tag'];
Additionally, is there anyway to mix formData + data correctly?
EDIT . the screenshots of browser's console
EDIT2 -----------------------------------------------------------
The thing is, it's gonna work if I remove
contentType: false,
processData: false
but the problem is If I deleted it also can't pass var formData input:file through URL. What do I suppose to do ?
'&chaID=' + chaID + '&row_number=' + row_number + '&tag=' + tag;on this'?chaID=' + chaID + '&row_number=' + row_number + '&tag=' + tag;you have no valid post data.FormData,?chaID=2&row_number=3&tag=7right now but still not work .__.