404错误,但在Codeigniter框架中来自JQuery Ajax的正确响应(404 Error but correct Response from JQuery Ajax in Codeigni

编程入门 行业动态 更新时间:2024-10-28 08:21:08
404错误,但在Codeigniter框架中来自JQuery Ajax的正确响应(404 Error but correct Response from JQuery Ajax in Codeigniter Framework)

这与SO上的另一个问题类似:

jQuery Ajax返回404错误,但正确的响应

但以上是非常特别的WordPress。 另外,我的直觉是我的问题与我的Apacher服务器设置有关,但我在这方面有点新手。

这是交易...我有这个Jquery AJAX代码:

events: function(start, end, callback) { $.ajax({ type: "POST", // This Works --> url: 'http://calendar.localhost/index.php/myfeed/', // This Fails --> //url: 'http://calendar.localhost/myfeed/', dataType: 'json', cache: false, data: { appointment_id: _appointmentId }, success: function(d) {.... }, error: function(x,s,e) {... } });

当我使用url和index.php时,一切正常。 但是,当我使用没有index.php的那个时,即使(json)数据看起来会恢复正常(见下文),我也会得到一个404错误。

另外,这发生在我最近升级到的新系统上:Debian 2.6.32(amd64)PHP 5.3.3 Apache 2.2.16

相同的代码(即/ myfeed或没有index.php)适用于我的旧系统:Fedora 8(yes,8 lol)PHP 5.2.x Apache 2.2.6

(请注意,最初我使用'/ myfeed'作为在我的“旧”系统上找到的URL参数,任何解决方案我都不需要对域进行硬编码,这是我可以接受的。)

因此,无论我在这三个版本中的其中一个(即,php,apache或linux版本中的更改)中遇到了一些差异,还是我需要在新的Apache设置中修改某些内容(我的猜测是根目录的内容' /'用于虚拟主机,我在本地主机上使用这个网站...也许它认为响应来自不同的域,但我不明白如果它可以与index.php一起工作但是失败没有它???)。

如果有人有我的解决方案或想法尝试,将不胜感激!

以下是Firebug针对非工作案例的详细信息:

POST http://calendar.localhost/myfeed 404找不到

Headers tab: Response Headersview source Date Tue, 22 Mar 2011 06:22:37 GMT Server Apache/2.2.16 (Debian) X-Powered-By PHP/5.3.3-7+squeeze1 Vary Accept-Encoding Content-Encoding gzip Content-Length 220 Keep-Alive timeout=15, max=90 Connection Keep-Alive Content-Type text/html Request Headersview source Host calendar.localhost User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16) Accept application/json, text/javascript, */*; q=0.01 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Content-Type application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With XMLHttpRequest Referer http://calendar.localhost/index.php/client Content-Length 36 Response tab: {"eventArray":[{"id":"2","notes":"test client Thurs","start":1299951000000,"end":1299960900000},{"id":"3","notes":"test bb334343","start":1300064400000,"end":1300068000000},{"id":"5","notes":"New appt dafdaf","start":1300462200000,"end":1300465800000}, {"id":"35","notes":"japan2","start":1300539600000,"end":1300545000000},{"id":"47","notes":"helo customer test","start":1300471200000,"end":1300475700000},{"id":"50","notes":"test 2 x email","start":1300455000000,"end":1300455900000}]}

另外:

〜mod_rewrite启用? 是的,我相信如此(我的CI页面应该重定向)。

在CI www目录下〜.htaccess? 是:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> # If we don't have mod_rewrite installed, all 404's # can be sent to index.php, and everything works as normal. # Submitted by: ElliotHaughin ErrorDocument 404 /index.php </IfModule>

谢谢,

彼得

PHP端代码(按要求):

public function viewEvent() { ... $appointmentData['startDate'] = $startDate; $appointmentData['startTime'] = $startTime; $data = array( 'eventData'=>$appointmentData ); echo json_encode($data); }

另外,Apache日志提供:

[Tue Mar 22 10:45:03 2011] [error] [client 127.0.0.1] File does not exist: /var/www/calendar/myfeed, referer: http://calendar.localhost/

This is similar to another issue on SO:

jQuery Ajax returning 404 Error, but correct Response

but the above is very wordpress-specific. Also, my gut feeling is that my problem has more to do with my Apacher server setup, but I'm somewhat of a newbie at that.

Here's the deal...I have this Jquery AJAX code:

events: function(start, end, callback) { $.ajax({ type: "POST", // This Works --> url: 'http://calendar.localhost/index.php/myfeed/', // This Fails --> //url: 'http://calendar.localhost/myfeed/', dataType: 'json', cache: false, data: { appointment_id: _appointmentId }, success: function(d) {.... }, error: function(x,s,e) {... } });

When I use the url with index.php, everything works fine. However when I use the one without index.php, I get a 404 error, even though the (json) data seeems to be coming back ok (see below).

Also, this is happening on a new system I recently upgraded to : Debian 2.6.32 (amd64) PHP 5.3.3 Apache 2.2.16

The same code (ie /myfeed or without index.php) works on my old system: Fedora 8 (yes, 8 lol) PHP 5.2.x Apache 2.2.6

(Note, initially I was using '/myfeed' for the url param which worked find on my "old" system. Any solution where I don't have to hardcode the domains would be acceptable to me.)

So either I'm hitting some difference in one of these 3 (ie, the change in php, apache, or linux versions), or there's something I need to modify in my new Apache setup (my guess is something with the root dir '/' for virtual hosts, which I'm using for this site on my localhost...perhaps it's thinking the response is from a different domain, but I don't see how that could be if it works with index.php but fails without it???).

If anyone has a solution or ideas for me to try that would be greatly appreciated!!!!

Here are details from Firebug for the non-working case:

POST http://calendar.localhost/myfeed 404 Not Found

Headers tab: Response Headersview source Date Tue, 22 Mar 2011 06:22:37 GMT Server Apache/2.2.16 (Debian) X-Powered-By PHP/5.3.3-7+squeeze1 Vary Accept-Encoding Content-Encoding gzip Content-Length 220 Keep-Alive timeout=15, max=90 Connection Keep-Alive Content-Type text/html Request Headersview source Host calendar.localhost User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16) Accept application/json, text/javascript, */*; q=0.01 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Content-Type application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With XMLHttpRequest Referer http://calendar.localhost/index.php/client Content-Length 36 Response tab: {"eventArray":[{"id":"2","notes":"test client Thurs","start":1299951000000,"end":1299960900000},{"id":"3","notes":"test bb334343","start":1300064400000,"end":1300068000000},{"id":"5","notes":"New appt dafdaf","start":1300462200000,"end":1300465800000}, {"id":"35","notes":"japan2","start":1300539600000,"end":1300545000000},{"id":"47","notes":"helo customer test","start":1300471200000,"end":1300475700000},{"id":"50","notes":"test 2 x email","start":1300455000000,"end":1300455900000}]}

Also :

~ mod_rewrite enabled? Yes, I belive so (my CI pages redirect as they should).

~ .htaccess in CI www directory? Yes:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> # If we don't have mod_rewrite installed, all 404's # can be sent to index.php, and everything works as normal. # Submitted by: ElliotHaughin ErrorDocument 404 /index.php </IfModule>

Thanks,

Peter

PHP-side code (by request):

public function viewEvent() { ... $appointmentData['startDate'] = $startDate; $appointmentData['startTime'] = $startTime; $data = array( 'eventData'=>$appointmentData ); echo json_encode($data); }

Also, Apache log is giving:

[Tue Mar 22 10:45:03 2011] [error] [client 127.0.0.1] File does not exist: /var/www/calendar/myfeed, referer: http://calendar.localhost/

最满意答案

解决:令人尴尬的是,ModRewrite未启用。 我只是想通过将垃圾文本放在等同于“if / else”语句的条件下,使modrewrite被启用或不启用,并且确实没有。 我会早些发现这一点,除了该网站展示的其他行为让我觉得modrewrite实际上已启用。 啊。

我希望我的白痴帮助别人节省一些时间! :)

Resolved: embarrassingly, ModRewrite was not enabled. I only figured this out by putting garbage text inside the equivalent of an "if/else" statement conditioned on modrewrite being enabled or not, and sure enough it wasn't. I would have found this earlier except the site was exhibiting other behavior that made me think modrewrite was actually enabled. ugh.

I hope my idiocy helps someone save some time in the future!! :)

更多推荐

本文发布于:2023-08-04 01:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但在   框架   正确   错误   Codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!