2014-04-04 121 views
0

我正在使用CodeIgniter。我创建了一个论坛,但是当我尝试对现有讨论发表评论时,我收到此错误:POST http://jaku0260.keaweb.dk//index.php/user/updatecomment 404 Not Found 165msCodeIgniter 404问题

上,你可以实际try for yourself同一站点:

用户:[email protected]

通行证:德尔菲诺

这里是表单代码:

<input type="text" class="form-control" id="<?php echo $post->postid;?>" placeholder="share your 

thoughts about this"> 
    <span class="input-group-btn"> 
    <button class="btn btn-default" onclick="hello(<?php echo $post->postid;?>);" 

type="button">Share</button> 
<script type="text/javascript"> 




function hello(id){ 

var data=document.getElementById(id).value; 
if(data !=""){ 

var hr = new XMLHttpRequest(); 
// Create some variables we need to send to our PHP file 
    var url = "<?php echo base_url()?>/index.php/user/updatecomment"; 
var vars = "postid="+id+"&comment="+data; 


hr.open("POST", url, true); 
// Set content type header information for sending url encoded variables in the request 
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
// Access the onreadystatechange event for the XMLHttpRequest object 
hr.onreadystatechange = function() { 
    if(hr.readyState == 4 && hr.status == 200) { 
     var return_data = hr.responseText; 

     document.getElementById(id+"comment").innerHTML= "<li style='list-style:none;margin-top: 10px;'><div class='row'><div class='col-lg-1'></div><div class='col-lg-10'><div class='input-group'><span class='input-group-btn'><img src='<?php echo base_url();?>assets/user/<?php echo $profpic;?>' class='commentboxpic'></span><span><span class='personnameclass'>Asad Ullah</span><span style='padding-left:5px;'>"+ data+"</span></span></div><!-- /input-group --></div><!-- /.col-lg-6 --></div><!-- /.row --></li>"+document.getElementById(id+"comment").innerHTML; 
     document.getElementById(id).value="";   

    } 
} 
// Send the data to PHP now... and wait for response to update the status div 
hr.send(vars); // Actually execute the request 
} 

} 

</script> 

这里的功能控制:

function updatecomment(){ 

if($this->session->userdata('userid')){ 
    $this->load->model('forum_model'); 
$id=$this->input->post('postid'); 

$userID=$this->session->userdata('userid'); 
$comment=$this->input->post('comment'); 

$this->forum_model->insertcomment($userID,$id,$comment); 


    echo 1; 
    } 
    else{ 

echo 0; 
    } 

型号:

function getkomments($id){ 
$this->db->where('forumid',$id); 
$this->db->from('forumcomment'); 
$this->db->join('user','forumcomment.userid=user.userid'); 

$query=$this->db->get(); 
if($query->num_rows>=1) 
    return $query->result(); 
return NULL; 



} 

function insertcomment($userID,$id,$comment){ 
$data=array(
    'userid'=>$userID, 
    'forumid'=>$id, 
    'comment'=>$comment 

    ); 
$this->db->insert('forumcomment',$data); 

return 1; 

} 

感谢您的帮助。

AJAX:

function hello(id){ 

var data=document.getElementById(id).value; 
if(data !=""){ 

var hr = new XMLHttpRequest(); 
// Create some variables we need to send to our PHP file 
var url = "<?php echo base_url()?>index.php/user/updatecomment"; 
var vars = "postid="+id+"&comment="+data; 


hr.open("POST", url, true); 
// Set content type header information for sending url encoded variables in the request 
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
// Access the onreadystatechange event for the XMLHttpRequest object 
hr.onreadystatechange = function() { 
    if(hr.readyState == 4 && hr.status == 200) { 
     var return_data = hr.responseText; 

     document.getElementById(id+"comment").innerHTML= "<li style='list-style:none; margin-top: 10px;'><div class='row'><div class='col-lg-1'></div><div class='col-lg-10'><div class='input-group'><span class='input-group-btn'><img src='<?php echo base_url();?>assets/user/5.jpg' class='commentboxpic'></span><span><span class='personnameclass'></span><span style='padding-left:5px;'>"+ data+"</span></span></div><!-- /input-group --></div><!-- /.col-lg-6 --></div><!-- /.row --></li>"+document.getElementById(id+"comment").innerHTML; 
     document.getElementById(id).value="";   


    } 
} 
// Send the data to PHP now... and wait for response to update the status div 
hr.send(vars); // Actually execute the request 
} 

} 

回答

1

检查URL是正确的,也许这种尝试:

var url = "<?php echo base_url()?>index.php/user/updatecomment"; 

还尝试编辑的.htaccess删除index.php文件,它将使容易指向一个网址,也会使它看起来更好。

+0

谢谢这帮助我,但是当我发布评论时,发布的人的名字是错误的是来自另一个用户。你能帮助我吗? –

+0

看看你是否每次登录时都会在会话中正确保存你的用户ID,在注销时也清除会话变量,如果没有,unset_userdata应该可以工作,也许你可以尝试通过ajax发送用户ID,希望它有帮助。 –

+0

感谢帮助我检查我的ajax。我想我需要添加该用户在该Ajax函数。 –