404 Error but correct answer from jQuery Ajax in Codeigniter Framework

This seems like another problem in SO:

jQuery Ajax returns 404 error but correct answer

but the above is very specific for Wordpress. Also, my gut feeling is that my problem is more about setting up the Apacher server, but I'm a little new to this.

Here's the deal ... I have a 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 url with index.php everything works fine. However, when I use one without index.php, I get a 404 error, even though the data (json) is returned in order (see below).

In addition, this happens on a new system that I recently upgraded to: Debian 2.6.32 (amd64) PHP 5.3.3 Apache 2.2.16

(../myfeed index.php) :   Fedora 8 (, 8 lol)   PHP 5.2.x   Apache 2.2.6

( : '/myfeed' url, . , , .

, - 3 (.. php, apache linux-), - Apache ( - - root dir '/' , ... , , , , , . 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 , ).

~.htaccess CI www? :

<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/
+3
3

: , ModRewrite . , if if else, modrewrite , , , . , , , , modrewrite . .

, - !:)

+9

, , , . htaccess ,

RewriteRule ^(.*)$ index.php/$1 [L]

, , , , , , .

0

Here you can find the perfect solution! The problem is the latest updates with codeigniter. Hope this saves someone a day or two! Happy coding! https://gist.github.com/philipptempel/4226750

0
source

All Articles