实际上我是 web 和 php 新手, 我正在建立一个网站, 我想在那里引入聊天 session ,但是,当用户单击插入按钮时,该按钮不起作用(无法将参数传递到另一个页面)
救救我......!!!
这是代码
chat_page.php
<input type="text" id="txtmsg" name="txtmsg" size="25"> <input type="button" value="send" onclick="sndmsg()">
jscript.js
function sndmsg() {
msg=document.getElementById('txtmsg').value;
$.post("insert.php",{u:un,m:msg},function(){ });
document.getElementById('txtmsg').value="";
}
插入.php
include("connec.php");
$chatmsg=mysql_real_escape_string($_REQUEST['m']);
$uname=mysql_real_escape_string($_REQUEST['u']);
echo $chatmsg;
echo $uname;
mysql_query("INSERT INTO `mdi_chat_msg`(`uname`, `chatmsg` ) VALUES ( '$uname','$chatmsg')") or die(mysql_error());
最佳答案
jscript.js 中的 un 是什么。也许,该参数是未知的。
$.post("insert.php",{u:un,m:msg},function(){ });
您应该声明 un 和 msg 变量;
var un, msg;
关于javascript - 如何使用ajax和$.post获取php页面中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32284450/