I got one input field named code, which i like to use in 2 php files. First php file checks the code on database. If successfull second php will generate a pdf file (and prints). Now the ajax request for the first php file works, but for the second php file the variable code isn't set (i checked form-data in chrome. In 2nd php file $_POST['code']
seems to be empty.
$(document).ready(function ()
{
$(document).on('submit', '#reg-form', function ()
{
$.post('lookup.php', $(this).serialize())
.done(function (data)
{
$("#reg-form").fadeOut('slow', function ()
{
$(".result").fadeIn('slow', function ()
{
// Just a hello ....
$(".result").html(data);
// Generate + Print PDF badge
$.post('generate_print.php',$(this).serialize())//<-- how do i get the code from form
});
});
})
.fail(function ()
{
alert('fail to submit the data');
});
return false;
});
});
In generate_print.php i have
$code = isset($_POST['code']) ? $_POST['code'] : 'this-should-not-be-shown';
For testing and this-should-not-be-shown generated :(
[EDIT] I change the js to see if I can get the var code
$(document).ready(function ()
{
$(document).on('submit', '#reg-form', function ()
{
var tmpCode = $("#code").val();//<-- here edit
$.post('lookup.php', $(this).serialize())
.done(function (data)
{
console.log("inner test "+tmpTest);//<-- here check
$("#reg-form").fadeOut('slow', function ()
{
$(".result").fadeIn('slow', function ()
{
$(".result").html(data);
// Generate + Print PDF badge
$.post('generate_print.php',tmpCode) //<-- here edit , not working
});
});
})
.fail(function ()
{
alert('fail to submit the data');
});
return false;
});
});