0
首先抱歉,即時通訊真的很大的begginer,我真的不明白的東西。Codeigniter jQuery的阿賈克斯選擇與滑動動畫
我正在建立一個小型caht形式我的用戶,並插入是好的。
我想說,當我插入我的聊天消息,之後,插入的消息將滑落,而我有點卡住了它。
我的jQuery
$('#chat_submit').on('click', function(e){
e.preventDefault();
var res = {
'msg' : $('#chat_msg').val(),
}
$.ajax({
type: 'POST',
url: '<?php echo base_url(); ?>main/send_chat',
data: res,
dataType: 'json',
success: function(data, html){
$('#chat_msg').removeAttr('value');
}
});
return false;
});
HTML和PHP
<div id="content">
<h2>Chat</h2>
<div id="chatbox">
<?php foreach ($chat as $ch): ?>
<?php
echo '
<div class="chat_post">
<span class="chat_time">'.date('H:i', strtotime($ch->added)).'</span>
<a href="'.base_url().'profile/user/'.$ch->uid.'" class="chat_name">'.$ch->first_name. " " .$ch->last_name.': </a>
<span class="chat_msg">'.$ch->msg.'</span>
</div>
';
?>
<?php endforeach; ?>
</div>
<?php echo form_open(base_url() . "main/send_chat"); ?>
<div id="feed_wrapp">
<input type="text" name="msg" id="chat_msg">
<input type="submit" value="Küldés" class="submit" id="chat_submit">
</div>
<?php echo form_close(); ?>
</div>
我試過很多方法,但即時通訊完全一無所知,可以請人指出我缺少什麼?在我的控制器
function send_chat()
{
$this->load->model('user/chat_model');
if($this->input->is_ajax_request())
{
$this->chat_model->chat_insert();
}
//redirect(base_url());
}
發送聊天功能,並在我的模型插入
function chat_insert()
{
$chat = array(
'uid' => $this->session->userdata('uid'),
'msg' => $this->input->post('msg')
);
$this->db->insert('pf_chat_post', $chat);
}
您好,非常感謝您的回覆,我更新了我的becuse我真的失去了問題,貼出我的querys,請你解釋如何在seuchat方法之後添加它? – Side 2012-03-19 11:28:52
編輯我的答案。 – 2012-03-19 11:42:28
感謝您的幫助 – Side 2012-03-19 11:48:00