Php 代码点火器404问题
我用的是CodeIgniter。我创建了一个论坛,但当我试图对现有的讨论发表评论时,我收到了以下错误:Php 代码点火器404问题,php,codeigniter,Php,Codeigniter,我用的是CodeIgniter。我创建了一个论坛,但当我试图对现有的讨论发表评论时,我收到了以下错误:POSThttp://jaku0260.keaweb.dk//index.php/user/updatecomment 404找不到165ms 在同一网站上,您实际上可以: 用户:jakub@mail.com 传球:德尔菲诺 以下是表格的代码: <input type="text" class="form-control" id="<?php echo $post->posti
POSThttp://jaku0260.keaweb.dk//index.php/user/updatecomment 404找不到165ms
在同一网站上,您实际上可以:
用户:jakub@mail.com
传球:德尔菲诺
以下是表格的代码:
<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 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;
}
谢谢你的帮助
阿贾克斯:
函数hello(id){
var data=document.getElementById(id).value;
如果(数据!=“”){
var hr=新的XMLHttpRequest();
//创建一些我们需要发送到PHP文件的变量
var url=“index.php/user/updatecomment”;
var vars=“postid=“+id+”&comment=“+data;
hr.open(“POST”,url,true);
//设置用于在请求中发送url编码变量的内容类型标头信息
hr.setRequestHeader(“内容类型”、“应用程序/x-www-form-urlencoded”);
//访问XMLHttpRequest对象的onreadystatechange事件
hr.onreadystatechange=函数(){
如果(hr.readyState==4&&hr.status==200){
var return_data=hr.responseText;
document.getElementById(id+“comment”).innerHTML=““+data+” “+document.getElementById(id+“comment”).innerHTML;
document.getElementById(id).value=“”;
}
}
//立即将数据发送到PHP…并等待更新status div的响应
hr.send(vars);//实际执行请求
}
}
检查url是否正确,可以尝试以下方法:
var url = "<?php echo base_url()?>index.php/user/updatecomment";
var url=“index.php/user/updatecomment”;
另外,尝试编辑.htaccess以删除index.php,这将使指向url更容易,也会使其看起来更好。谢谢这一帮助,但当我发布评论时,发布错误的人的姓名来自另一个用户。你能帮我吗?看看你每次登录时是否在会话中正确保存了你的用户id,注销时也清除了会话变量,取消设置userdata应该可以工作,如果不行,也许你可以尝试通过ajax发送用户id,希望有帮助。谢谢你的帮助,我检查了我的ajax。我想我需要在ajax函数中添加用户。没有必要使用ajax添加用户,因为您在登录时已经获得了用户,但是ajax也可以工作,很乐意提供帮助!如果我的回答有帮助,你能接受我的回答吗?所以我可以在这里赢得一些声誉:我尝试了,但没有成功。您可以用正确的方式更改我的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
}
}
var url = "<?php echo base_url()?>index.php/user/updatecomment";