我对 javascript json 有疑问。我可以从 ajax 帖子中获取价值。
像这样的脚本。
<script> function makeAjaxCall()
{
$.ajax({
type: "post",
data: $('#form1').serialize(),
url: "http://localhost/SPKM/new_file.php",
cache: false,
success: function(json){
var obj = jQuery.parseJSON(json);
var r = obj['STATUS'];
alert(r);
}
});
}
</script>
和这样的形式..
<form name="form1" id="form1">
<input type="text" name="value" id="value">
<input type="button" name="Submit" onkeypress="makeAjaxCall()">
</form>
像这样的new_file.php..
<?
$query = "SELECT sum(in)-sum(out) AS total FROM $tableName";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$phpVar = array("STATUS",$row['total']));
echo json_encode($phpVar);
}
?>
当我单击按钮时结果未定义.. 感谢您的帮助..