从javascript调用的Codeigniter路径

Codeigniter Path called from javascript

本文关键字:Codeigniter 路径 调用 javascript      更新时间:2023-09-26

我有两个Codeigniter实例,在View/Javascript文件中执行Ajax调用,如下所示。在一个实例中,调用被解析为"http://www.myhost.com/myapp/index.php/api/api_controller/get.json",而在另一个实例中,它是"http://www.myhost.com/myapp/api/api_controller/get.json",没有'index.php'。

谁能告诉我为什么?

谢谢!

var url = "api/generic_item_api/get.json"
$.ajax({
        type : 'GET',
        url: url,
        async: false,
        dataType : 'json',
        success : function(data){       
           // do something          
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
        }
    });

默认情况下,codeigniter在url中包含index.php

你需要删除index.php使用。htaccess

RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

检查这里(删除index.php文件):

http://ellislab.com/codeigniter/user-guide/general/urls.html