【发布时间】:2012-11-25 10:35:58
【问题描述】:
我正在使用立即调用函数模式,但这没有传递 id
1.当用户点击$user时,传入id,出现聊天窗口
echo "<div class='boxbottom'><a href='#' onclick=chat_com_one($id);> >$user</a><br></div>";
2.函数 chatcom_load_one 不断检查,是否有任何来自 id 的消息传递给 chatcom_load_one 函数。
但问题是 onclick 函数确实传递了 id 但立即调用的函数没有将 id 传递给 post 函数。
发送消息也很慢?
请帮助或建议任何替代方法,我认为错误是在 chat_load_one 模式中。
function chat_com_one(id) {
$('#chatcom').show('fast');
(function chatcom_load_one(id) {
$.post('sendchat2.php', {
option: 'chatcom_load_one',
tocom: id
}, function (data) {
$('#chatcom #commid #commidwin').html(data);
setTimeout(chatcom_load_one(id), 1000);
});
}());
$('#chatcom_send').click(function () {
var text = document.getElementById('chatcom_text').value;
$.post('sendchat2.php', {
option: 'chat_com_send_one',
text: text,
tocom: id
}, f
function (data) {
document.getElementById('chatcom_text').value = '';
});
});
}
在我的服务器上发送函数
if($_REQUEST['option']=='chat_com_send_one'){
$session=new $session;
$text=mysqli_real_escape_string($db3->connection,$_POST['text']);
$tocom=mysqli_real_escape_string($db3->connection,$_POST['tocom']);
$sql=mysqli_query($db3->connection,"INSERT INTO chat_com(fro,tocom,mesg,time) VALUES ('$session->userid','$tocom','$text',CURRENT_TIMESTAMP)");
}
【问题讨论】:
-
你在最后一个
$.post:f function有语法错误。 -
@tjameson 我怎样才能消除这个错误
-
我在回答中做了一系列修复,希望对您有所帮助。
标签: php javascript