我有一个名为code的输入字段,我喜欢在2个php文件中使用。第一个php文件检查数据库上的代码。如果成功第二个php将生成一个pdf文件(并打印)。现在第一个php文件的ajax请求有效,但是对于第二个php文件,没有设置变量代码(我在chrome中检查了form-data。在第二个php文件中$_POST['code']
似乎是空的。
$(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;
});
});
在generate_print.php中我有
$code = isset($_POST['code']) ? $_POST['code'] : 'this-should-not-be-shown';
对于测试而且这应该不会显示生成:(
[编辑] 我更改了js以查看是否可以获取var代码
$(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;
});
});