Codeigniter聊天应用程序未提交表单数据,并且在javascript控制台中显示500内部服务器错误
我试图使用codeigniter框架实现一个聊天应用程序,但是在表单提交时,表单数据没有被提交,提交按钮被禁用。当我在javascript控制台上检查时,我得到一个错误500,url localhost/biko/chat/conv/xsapSHKs/msg的内部服务器错误,它应该获取新消息。我非常熟悉PHP,但不太擅长ajax或javascript。我们将非常感谢您的帮助。下面是我的控制器、模型和视图 控制器(chat.php) 型号Codeigniter聊天应用程序未提交表单数据,并且在javascript控制台中显示500内部服务器错误,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我试图使用codeigniter框架实现一个聊天应用程序,但是在表单提交时,表单数据没有被提交,提交按钮被禁用。当我在javascript控制台上检查时,我得到一个错误500,url localhost/biko/chat/conv/xsapSHKs/msg的内部服务器错误,它应该获取新消息。我非常熟悉PHP,但不太擅长ajax或javascript。我们将非常感谢您的帮助。下面是我的控制器、模型和视图 控制器(chat.php) 型号 public function save($action)
public function save($action) {
$from = $this->input->post('mid', TRUE);
$descId = $this->input->post('id', TRUE);
$to = $this->input->post('fid', TRUE);
$msg = $this->input->post('text', TRUE);
$created = mktime();
switch ($action):
case 'new':
$descId = $this->input->post('id', TRUE);
$created = mktime();
$msg = $this->input->post('text', TRUE);
$from = $this->input->post('mid', TRUE);
$to = $this->input->post('fid', TRUE);
if(empty($msg)){
$json = array('status' => 0, 'msg'=> 'Enter your message!.');
}else{
$data = array (
'desc_id' => $descId,
'from' => $from,
'to' => $to,
'msg' => $msg,
'time' => $created,
'status' => '1'
);
$qur = $this->db->insert('chat_msg', $data);
$insertId = $this->db->insert_id();
if($qur){
$this->db->where('id', $insertId);
$qurGet = $this->db->get('chat_msg');
while($row = $qurGet->row_array()){
$json = array('status' => 1, 'msg' => $row['msg'], 'lid' => $insertId, 'time' => $row['time']);
}
} else {
$json = array('status' => 0, 'msg'=> 'Unable to process request.');
}
}
break;
case 'msg':
$from = $this->input->post('mid', TRUE);
$to = $this->input->post('fid', TRUE);
$lid = $this->input->post('lid', TRUE);
if(empty($from)){
} else {
//print_r($_POST);
$where = array('to' => $to, 'from' => $from, 'status' => '1');
$this->db->where($where);
$qur = $this->db->get('chat_msg');
if($qur->num_rows() > 0){
$json = array('status' => 1);
}else{
$json = array('status' => 0);
}
}
break;
case 'NewMsg':
$from = $this->input->post('mid', TRUE);
$to = $this->input->post('fid', TRUE);
$where = array('to' => $to, 'from' => $from, 'status' => '1');
$this->db->where($where);
$this->db->order_by('id', 'desc');
$this->db->limit(1);
$qur = $this->db->get('chat_msg');
while($rw = $qur->row_array()){
$json = array('status' => 1, 'msg' => '<div>'.$rw['msg'].'</div>', 'lid' => $rw['id'], 'time'=> $rw['time']);
}
// update status
$where = array('to' => $to, 'from' => $from);
$this->db->where($where);
$qur = $this->db->update('chat_msg');
break;
endswitch;
$this->output->set_content_type('application/json');
return $this->set_output($json);
}
公共功能保存($action){
$from=$this->input->post('mid',TRUE);
$descId=$this->input->post('id',TRUE);
$to=$this->input->post('fid',TRUE);
$msg=$this->input->post('text',TRUE);
$created=mktime();
开关($action):
“新”案例:
$descId=$this->input->post('id',TRUE);
$created=mktime();
$msg=$this->input->post('text',TRUE);
$from=$this->input->post('mid',TRUE);
$to=$this->input->post('fid',TRUE);
if(空($msg)){
$json=array('status'=>0,'msg'=>'输入您的消息!);
}否则{
$data=数组(
'desc_id'=>$descId,
'from'=>$from,
'至'=>$至,
'msg'=>$msg,
“时间”=>$created,
“状态”=>“1”
);
$qur=$this->db->insert('chat_msg',$data);
$insertId=$this->db->insert_id();
如果($qur){
$this->db->where('id',$insertId);
$qurGet=$this->db->get('chat_msg');
而($row=$qurGet->row\U array()){
$json=array('status'=>1,'msg'=>$row['msg'],'lid'=>$insertId,'time'=>$row['time']);
}
}否则{
$json=array('status'=>0,'msg'=>'无法处理请求');
}
}
打破
案例“msg”:
$from=$this->input->post('mid',TRUE);
$to=$this->input->post('fid',TRUE);
$lid=$this->input->post('lid',TRUE);
if(空($from)){
}否则{
//打印(邮政美元);
$where=array('to'=>$to',from'=>$from',status'=>'1');
$this->db->where($where);
$qur=$this->db->get('chat_msg');
如果($qur->num_rows()>0){
$json=array('status'=>1);
}否则{
$json=array('status'=>0);
}
}
打破
案例“NewMsg”:
$from=$this->input->post('mid',TRUE);
$to=$this->input->post('fid',TRUE);
$where=array('to'=>$to',from'=>$from',status'=>'1');
$this->db->where($where);
$this->db->order_by('id','desc');
$this->db->limit(1);
$qur=$this->db->get('chat_msg');
而($rw=$qur->row\u array()){
$json=array('status'=>1,'msg'=>'.$rw['msg'].','lid'=>$rw['id'],'time'=>$rw['time']);
}
//更新状态
$where=array('to'=>$to',from'=>$from);
$this->db->where($where);
$qur=$this->db->update('chat_msg');
打破
终端开关;
$this->output->set_content_type('application/json');
返回$this->set_输出($json);
}
查看
<?php
if ($this->auth_user_id != $converse['from']) { $fid = $this->auth_user_id; } else { $fid = $converse['to']; }
$myid = $this->auth_user_id;
?>
<script src="<?php echo WEBSITE_URL ?>assets/chat/jquery.min.js"></script>
<script src="<?php echo WEBSITE_URL ?>assets/chat/moment.min.js"></script>
<script src="<?php echo WEBSITE_URL ?>assets/chat/livestamp.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>assets/chat/style.css">
<div class="chatcontainer">
<div class="chat" id="chat">
<div class="stream" id="cstream">
</div>
</div>
<div class="msg">
<form method="post" id="msenger" action="">
<textarea name="msg" id="msg-min"></textarea>
<input name="id" type="hidden" value="<?php echo $converse['id'] ?>" />
<input type="hidden" name="mid" value="<?php echo $myid;?>">
<input type="hidden" name="fid" value="<?php echo $fid;?>">
<input type="submit" value="Send" id="sb-mt">
</form>
</div>
<div id="dataHelper" last-id=""></div>
</div>
<script type="text/javascript">
$(document).keyup(function(e){
if(e.keyCode == 13){
if($('#msenger textarea').val().trim() == ""){
$('#msenger textarea').val('');
}else{
$('#msenger textarea').attr('readonly', 'readonly');
$('#sb-mt').attr('disabled', 'disabled'); // Disable submit button
sendMsg();
}
}
});
$(document).ready(function() {
$('#msg-min').focus();
$('#msenger').submit(function(e){
$('#msenger textarea').attr('readonly', 'readonly');
$('#sb-mt').attr('disabled', 'disabled'); // Disable submit button
sendMsg();
e.preventDefault();
});
});
function sendMsg(){
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/new',
data: $('#msenger').serialize(),
dataType: 'json',
success: function(rsp){
$('#msenger textarea').removeAttr('readonly');
$('#sb-mt').removeAttr('disabled'); // Enable submit button
if(parseInt(rsp.status) == 0){
alert(rsp.msg);
}else if(parseInt(rsp.status) == 1){
$('#msenger textarea').val('');
$('#msenger textarea').focus();
//$design = '<div>'+rsp.msg+'<span class="time-'+rsp.lid+'"></span></div>';
$design = '<div class="float-fix">'+
'<div class="m-rply">'+
'<div class="msg-bg">'+
'<div class="">'+
'Me'+
'</div>'+
'<div class="msgA">'+
rsp.msg+
'<div class="">'+
'<div class="msg-time time-'+rsp.lid+'"></div>'+
'<div class="myrply-i"></div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('#cstream').append($design);
$('.time-'+rsp.lid).livestamp();
$('#dataHelper').attr('last-id', rsp.lid);
$('#chat').scrollTop($('#cstream').height());
}
}
});
}
function checkStatus(){
$fid = '<?php echo $fid; ?>';
$mid = '<?php echo $myid; ?>';
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/msg',
data: {fid: $fid, mid: $mid, lid: $('#dataHelper').attr('last-id')},
dataType: 'json',
cache: false,
success: function(rsp){
if(parseInt(rsp.status) == 0){
return false;
}else if(parseInt(rsp.status) == 1){
getMsg();
}
}
});
}
// Check for latest message
setInterval(function(){checkStatus();}, 200);
function getMsg(){
$fid = '<?php echo $fid; ?>';
$mid = '<?php echo $myid; ?>';
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/NewMsg',
data: {fid: $fid, mid: $mid},
dataType: 'json',
success: function(rsp){
if(parseInt(rsp.status) == 0){
//alert(rsp.msg);
}else if(parseInt(rsp.status) == 1){
$design = '<div class="float-fix">'+
'<div class="f-rply">'+
'<div class="msg-bg">'+
'<div class="">'+
$fid+
'</div>'+
'<div class="msgA">'+
rsp.msg+
'<div class="">'+
'<div class="msg-time time-'+rsp.lid+'"></div>'+
'<div class="myrply-f"></div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('#cstream').append($design);
$('#chat').scrollTop ($('#cstream').height());
$('.time-'+rsp.lid).livestamp();
$('#dataHelper').attr('last-id', rsp.lid);
}
}
});
}
</script>
尝试更改$config['allowed\u uri\u chars']=''
请尝试并让我知道。可能重复我尝试了该问题中提供的解决方案,但没有一个有效。请尝试使用url:“/conv/refresh/”,
我相信这不是重复的帖子,因为我的配置参数与上一个问题中的参数类似。因此,我认为这是不一样的,但相关的。
<?php
if ($this->auth_user_id != $converse['from']) { $fid = $this->auth_user_id; } else { $fid = $converse['to']; }
$myid = $this->auth_user_id;
?>
<script src="<?php echo WEBSITE_URL ?>assets/chat/jquery.min.js"></script>
<script src="<?php echo WEBSITE_URL ?>assets/chat/moment.min.js"></script>
<script src="<?php echo WEBSITE_URL ?>assets/chat/livestamp.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>assets/chat/style.css">
<div class="chatcontainer">
<div class="chat" id="chat">
<div class="stream" id="cstream">
</div>
</div>
<div class="msg">
<form method="post" id="msenger" action="">
<textarea name="msg" id="msg-min"></textarea>
<input name="id" type="hidden" value="<?php echo $converse['id'] ?>" />
<input type="hidden" name="mid" value="<?php echo $myid;?>">
<input type="hidden" name="fid" value="<?php echo $fid;?>">
<input type="submit" value="Send" id="sb-mt">
</form>
</div>
<div id="dataHelper" last-id=""></div>
</div>
<script type="text/javascript">
$(document).keyup(function(e){
if(e.keyCode == 13){
if($('#msenger textarea').val().trim() == ""){
$('#msenger textarea').val('');
}else{
$('#msenger textarea').attr('readonly', 'readonly');
$('#sb-mt').attr('disabled', 'disabled'); // Disable submit button
sendMsg();
}
}
});
$(document).ready(function() {
$('#msg-min').focus();
$('#msenger').submit(function(e){
$('#msenger textarea').attr('readonly', 'readonly');
$('#sb-mt').attr('disabled', 'disabled'); // Disable submit button
sendMsg();
e.preventDefault();
});
});
function sendMsg(){
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/new',
data: $('#msenger').serialize(),
dataType: 'json',
success: function(rsp){
$('#msenger textarea').removeAttr('readonly');
$('#sb-mt').removeAttr('disabled'); // Enable submit button
if(parseInt(rsp.status) == 0){
alert(rsp.msg);
}else if(parseInt(rsp.status) == 1){
$('#msenger textarea').val('');
$('#msenger textarea').focus();
//$design = '<div>'+rsp.msg+'<span class="time-'+rsp.lid+'"></span></div>';
$design = '<div class="float-fix">'+
'<div class="m-rply">'+
'<div class="msg-bg">'+
'<div class="">'+
'Me'+
'</div>'+
'<div class="msgA">'+
rsp.msg+
'<div class="">'+
'<div class="msg-time time-'+rsp.lid+'"></div>'+
'<div class="myrply-i"></div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('#cstream').append($design);
$('.time-'+rsp.lid).livestamp();
$('#dataHelper').attr('last-id', rsp.lid);
$('#chat').scrollTop($('#cstream').height());
}
}
});
}
function checkStatus(){
$fid = '<?php echo $fid; ?>';
$mid = '<?php echo $myid; ?>';
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/msg',
data: {fid: $fid, mid: $mid, lid: $('#dataHelper').attr('last-id')},
dataType: 'json',
cache: false,
success: function(rsp){
if(parseInt(rsp.status) == 0){
return false;
}else if(parseInt(rsp.status) == 1){
getMsg();
}
}
});
}
// Check for latest message
setInterval(function(){checkStatus();}, 200);
function getMsg(){
$fid = '<?php echo $fid; ?>';
$mid = '<?php echo $myid; ?>';
$.ajax({
type: 'post',
url: '<?php echo WEBSITE_URL .''. uri_string() ?>/NewMsg',
data: {fid: $fid, mid: $mid},
dataType: 'json',
success: function(rsp){
if(parseInt(rsp.status) == 0){
//alert(rsp.msg);
}else if(parseInt(rsp.status) == 1){
$design = '<div class="float-fix">'+
'<div class="f-rply">'+
'<div class="msg-bg">'+
'<div class="">'+
$fid+
'</div>'+
'<div class="msgA">'+
rsp.msg+
'<div class="">'+
'<div class="msg-time time-'+rsp.lid+'"></div>'+
'<div class="myrply-f"></div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('#cstream').append($design);
$('#chat').scrollTop ($('#cstream').height());
$('.time-'+rsp.lid).livestamp();
$('#dataHelper').attr('last-id', rsp.lid);
}
}
});
}
</script>