I am trying to pass a PHP variable to JQUERY. I tried the following script but the var 'id' is not been passed to upload_avatar.php. Guess i am making some mistake. Can anyone help me.
$(document).ready(function (e) {
$("#uploadForm").on('submit',(function(e) {
e.preventDefault();
var id = '<?php echo $id; ?>';
$.ajax({
url: "upload_avatar.php",
type: "POST",
data: new FormData(this)
contentType: false,
cache: false,
processData:false,
success: function(data)
{
$("#targetLayer").html(data);
},
error: function()
{
}
});
}));
});
data: {id: id},var id = ...does not include it in theformdata that you are sending through to your PHP page. You need to explicitly add theidvalue into the form data, or create an object that contains your form data and theid.var id = '<?php echo $id; ?>';is ok, but you not useidany where after that