如何发送和接收值?
我做错了什么?
jQuery:点击保存按钮
$("#budget_submit").click(function(){
var budget = $("#budget_cardno").val();
$.ajax({
type: 'POST',
dataType: "json",
url: 'budget.php',
data: budget,
success: function(data){
if(data.success == true)
alert(data.message);
}
});
});
html:
<form method="post" id="budgetform">
<fieldset>
<ul>
<li>
<label>CARD NUMBER</label>
<input name="budget_cardno" id="budget_cardno" />
</li>
<li>
<label>MONTHLY BUDGET</label>
<input name="budget_monthly" id="budget_monthly" />
</li>
<li>
<input class="submit" id="budget_submit" name="budget_submit" type="submit" value="Save"/>
</li>
</ul>
</fieldset>
</form>
php:
<?php
$dbhost = '#';
$dbuser = '#';
$dbpass = '#';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$cardNo = $_POST['budget']; #This statement does not work.
if($cardNo == "")
{
mysql_close($conn);
$data = array('success' => true, 'message' => 'ENTER DETAILS');
echo json_encode($data);
}
else
{
}
?>
如何将价值预算发送到 PHP 文件并将其存储在 $cardNo 中并返回消息?
我不想在客户端检查条件,因为我有其他条件来检查哪些需要数据库中的数据。