function SubmitData(){
var postData = $("#xForm").serializeArray();
$.ajax({
type: "POST",
url: "mail.php",
data: postData,
success:function(data){
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log("Failure sending data");
}
});
}
$('#sub-comfirm').on('submit', function (e){
e.preventDefault();
SubmitData();
});
function CreateImagePost(imgValue){
var pImg = $("#mydata");
var inputBlock = "";
inputBlock += '<input type="hidden" id="canvasData" name="canvasData">';
pImg.html(inputBlock);
var element = document.getElementById("canvasData");
element.value = imgValue;
}
My goal is to use serializeArray to get all my input data through PHP. The problem arises when adding the input "canvasData" using the function CreateImagePost; my PHP does not receive the data at all.
However, if I directly add the input "canvasData" to the HTML field, the data successfully passes through to my PHP. Why can't I pass my data when adding the input using a function?