1
我在我的代码中使用了一个简单的ajax函数,它在本地主机中工作,但是当我上传代码时,它不起作用! 这是我在视图脚本:错误500(内部服务器错误)在codeigniter中使用ajax
<script type="text/javascript">
function active(int)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("frm_radio").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","<?php echo site_url("admin/groups/active_img/".$gallery_name."/".$gallery_id)."/"?>"+int,true);
xmlhttp.send();
}
</script>
和我的html代码:
<form id = "frm_radio">
.
.
.
<input type="radio" id="radio" name="active" value="'.$item -> id.'" onclick="active(this.value)"/>
.
.
.
</form>
,并在我的控制器我有active_img
function active_img($gallery_name, $gallery_id, $itemID) {
$name = $gallery_name . "_id";
$actived = $this -> gallery_model -> getitems(NULL, array("active" => 1, $name => $gallery_id));
$actived[0] -> active = 0;
$this -> gallery_model -> additem($actived[0], $actived[0] -> id);
$insert_vars["active"] = 1;
$this -> gallery_model -> additem($insert_vars, $itemID);
return true;
}
与名称的功能有一些单选按钮选择什么图像必须是活动的,当调用函数active_img时,它会改变我的数据库中的某些值并返回true,它在我的localhost中工作,但在服务器中它是n不工作!当我调试我的代码,我得到这个错误:
GET http://example.com/admin/groups/active_img/products/4/10 500 (Internal Server Error) 4:146
active 4:146
onclick 4:183
XHR finished loading: "http://example.com/admin/groups/active_img/products/4/10".
很有可能是PHP错误,并且您的服务器无法显示它 - 相反,它会抛出“内部服务器错误”。检查您的服务器日志以获取关于错误的更多详细信 – adrian7
你有没有加入csrf保护? –