douhuang1973 2014-04-04 16:33
浏览 32
已采纳

CodeIgniter 404问题

I'm using CodeIgniter. I created a forum but when I try to comment on an existing discussion I receive this error: POST http://jaku0260.keaweb.dk//index.php/user/updatecomment 404 Not Found 165ms.

On the same site you can actually try for yourself:

User: jakub@mail.com

Pass: delfino

Here is the code for the form:

<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>

Here the function control:

    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;
     }

Model:

  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;

}

Thanks for help.

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条回答 默认 最新

  • douyijin7741 2014-04-04 17:52
    关注

    Check if the url is correct, maybe trying with this:

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

    Also try to edit the .htaccess to remove the index.php, it will make easier pointing to a url and also will make it look better.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决