我已经看过很多关于我的问题的其他解决方案,但似乎都没有。我试图将多个JavaScript变量传递给Php。目前,我正在尝试使用Ajax:
$.ajax({
url: "yup.php",
data: {'Sal': Sal,
'TaxReb': TaxReb,
'RetInv': RetInv,
'IntSave': IntSave,
'Pen': Pen,
'Dividends': Dividends,
'Wages':Wages,
'Loans':Loans,
'Benefits':Benefits,
'IncOther': IncOther,
'Tax': Tax ,
'Groc': Groc ,
'Take':Take ,
'Rent': Rent ,
'Elec': Elec ,
'Trans': Trans ,
'Mort': Mort ,
'LoanPay':LoanPay ,
'Goods': Goods ,
'ExpOther': ExpOther ,
'TotalInc':TotalInc ,
'TotalExp': TotalExp ,
'NetInc':NetInc},
type:"post",
success:function(output){
alert(output);
//window.location.href='yup.php',
这些变量附加了数值(选中,它们不是问题)。我将它命名为是因为它仅用于测试目的。使用警报它输出我想要的东西,它会弹出一个小窗口。但是,当我实际进入页面时,我得到了未定义的索引错误。
注意:未定义的索引:第2行的C:\ xampp \ htdocs \ example \ yup.php中的Sal
它为我试图通过的所有变量做到了这一点。我尝试删除alert
和function(output)
,但它并没有改变任何内容。我计划之后将PHP变量写入数据库。任何帮助表示赞赏。
我的Php是这样的:
<?php $Sal = $_POST['Sal'];
$TaxReb = $_POST['TaxReb'];
$RetInv = $_POST['RetInv'];
$IntSave = $_POST['IntSave'];
$Pen = $_POST['Pen'];
$Dividends = $_POST['Dividends'];
$Wages = $_POST['Wages'];
$Loans = $_POST['Loans'];
$Benefits = $_POST['Benefits'];
$IncOther = $_POST['IncOther'];
$Tax = $_POST['Tax'];
$Groc = $_POST['Groc'];
$Take = $_POST['Take'];
$Rent = $_POST['Rent'];
$Elec = $_POST['Elec'];
$Trans = $_POST['Trans'];
$Mort = $_POST['Mort'];
$LoanPay = $_POST['LoanPay'];
$Goods = $_POST['Goods'];
$ExpOther = $_POST['ExpOther'];
$TotalInc = $_POST['TotalInc'];
$TotalExp = $_POST['TotalExp'];
$NetInc = $_POST['NetInc'];
echo //all the variables;?><br>