我試圖使用POST傳遞變量從try.htm到chat.php
爲try.htm的代碼是:
<head>
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type = "text/javascript">
function yo() {
var text = $("#msg").val();
$.post("chat.php",msg:text);
}
</script>
</head>
<body>
<input type="text" id="msg" onkeyup="yo()">
<div id="display">Change</div>
</body>
爲chat.php的代碼是:
<?php
$msg=$_POST['msg'];
mysql_connect("localhost","root");
mysql_select_db("user");
mysql_query("INSERT INTO user (name,pwd,status) VALUES ('$msg','work','0')") or die(mysql_error());
?>
問題是'msg'變量似乎沒有傳遞到chat.php! 有什麼問題?
其實你應該得到語法/解析錯誤。 – 2010-08-04 13:03:26