JQuery得到错误404,但可以在Firebug中看到响应


JQuery getting error 404 but can see the response in Firebug

我的网站是在Codeigniter中开发的,使用JQuery-post方法检索数据,它显示404未找到错误,而我在firebug中看到它显示了正确的输出。

它在本地系统中运行良好。我的网站在实时实例上处于子域下,这可能会导致问题?。

请提示可能是什么问题。

这是我的htaccess文件

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule> 

以下是萤火虫的反应细节

Connection  Keep-Alive
Content-Type    text/html
Date    Mon, 23 Jul 2012 12:28:26 GMT
Keep-Alive  timeout=3, max=29
Server  Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 mod_fcgid/2.3.6
Transfer-Encoding   chunked
X-Powered-By    PHP/5.2.17
Request Headers
Accept  text/html, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive

这是我的代码

function updatepanel()
{
$.post("http://svims.noq.co.in/svims/get_token/28" ,
function (d)
{
    $("#tokenview").html(d);
}
);
}

这是萤火虫的反应。

"网络错误:找不到404-http://svims.noq.co.in/svims/token_generator"

令牌生成器岗位http://svims.noq.co.in/svims/get_token/28

404未找到2.36s

========================================问题是,子域名称和控制器名称不应该相同。我重命名了控制器的名称,它运行良好。

有两件事需要检查。。。

编号1

除非绝对需要,否则不要对ajax请求使用完整的URL。。

$.post("http://svims.noq.co.in/svims/get_token/28" ,
//Should Become:
$.post("/svims/get_token/28" ,

编号2

确保你没有回显任何内容,也没有将任何错误或通知转储到你的页面上,因为这会导致请求失败。按chrome中的F12(Cmd+J)打开开发人员工具包,然后转到网络选项卡,单击底部的xhr,然后再次提交你的ajax,并等待POST返回,单击预览并查看它返回的内容。。在SO…上看到这个问题

Chrome 中的请求监控

问题是,子域名称和控制器名称不应该相同。重命名控制器名称,效果良好。

另一个注意事项:一些网络主机默认安装子目录/子域,如/stats和/logs,如果您的网络主机有它们,您可能会收到CI 的404错误

我在子域中创建了一个应用程序,并将一个控制器命名为"stats",即使最终内容是正确的,也会得到404错误标头。更改控制器名称后,错误消失了。