【发布时间】:2014-03-09 08:54:18
【问题描述】:
我正在使用 CodeIgniter ..我无法从控制器访问该方法
我的视图中有这个脚本
<script>
function showHint(str){
if (str.length==0){
document.getElementById("txtHint").innerHTML="";
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/ajaxSearch",true);
xmlhttp.send();
}
</script>
我有一个名为 ajax 的控制器,其方法是 ajaxSearch()
public function ajaxSearch(){
echo "received";
}
文件夹结构
htdocs/
AjaxTry/
AjaxSearchingMVC/
application/
controller/
ajax.php //controller
ajaxSearch() //method
views/
view_ajax.php // here is where the script is written
这可能是什么问题?
【问题讨论】:
-
can't access是什么意思?调试器控制台中是否有任何错误? -
无法访问该方法.. 它说.. HTTP/1.1 404 Not Found .. 它指向 my_base_url/ajax/ajaxSearch
-
当然你也试过
"/ajax/ajaxSearch"? -
我试了一下,url变成localhost/ajax/ajaxSearch
-
@Katherine:我不知道你是如何在 PhP 中做到这一点的,但在 ASP.NET MVC 中,我们将目标 url 从服务器发送到数据属性中的客户端,或者与服务器总是类似的无论发布到哪个服务器/域,都可以使用完整的 URL。在 ASP/NET MVC 中,我们有像
URL.Action('action', 'controller')这样的服务器端 C# 助手,它返回完整且正确的 URL。我不知道 PhP 中的等价物是什么。
标签: javascript php codeigniter directory-structure