jQuery - GET News.html 404 (Not Found)
ajax, jquery, php
Solution
This smells a bit like a same-origin policy issue. The path you are specifying may be causing the issue. Try
$.ajax({
url: "/News.html",
cache: false,
}).done(function(data) {
$("#content").load(data);
});
And let me (us) know if that helps.
Problem
For some reason, this doesn't work: ``` $.ajax({ url: "News.html", cache: false, }).done(function(data) { $("#content").load(data); }); ``` It gives me: ``` GET http://127.0.0.1/News.html 404 (Not Found) ``` But for whatever reason, opening that url manually (copy paste the url) works just fine. And i thought it had something to do with browser cache at first so i added the `cache: false` option to the ajax function but even then.. argh.. Also it does not show up as a requested URL in my `access.log` file.. For information i guess, i'm running: - lighttpd - php as fast-cgi via localhost:port - mapped .html => .php - Running OpenBSD 5.3 and uncommented (in `/etc/php.ini`): - cgi.fix_pathinfo=1 Also: ``` # ls *.html News.html index.html ``` And here's the request headers for `News.html`: ``` Request URL:http://127.0.0.1/News.html Request Method:GET Status Code:404 Not Found ``` Request Headers ``` Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Host:127.0.0.1 Referer:http://127.0.0.1/index.php User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36 X-Requested-With:XMLHttpRequest ``` Response Headers ``` Content-type:text/html Date:Tue, 16 Jul 2013 21:55:05 GMT Server:lighttpd/1.4.32 Transfer-Encoding:chunked X-Powered-By:PHP/5.3.21 ``` Checkpoint Conclusion from the comments so far is that this might not be a jQuery issue at all. Considering that the server responds with all the data (i've checked raw data sent) and it contains everything, but the response header says `404`. Meaning, the data is found but the header says 404... it's odd to say the least.. curl test ``` curl 'http://127.0.0.1/News.html' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: 127.0.0.1' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://127.0.0.1/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed Here you'll soon find a facebook feed, among other things :) ``` Zerkms test ``` # echo "wham bam" > zerkms_doesnt_believe.html # ``` Config files - lighttpd.conf - php-5.3.ini Error logs and what not - lighttpd-error.log cURL test Manual FastCGI test via a Python client: ``` # python fcgi_app.py {'FCGI_MAX_CONNS': '1', 'FCGI_MPXS_CONNS': '0', 'FCGI_MAX_REQS': '1'} ``` After some tinkering, i figured out how the FastCGI protocol works and i found a client that matched my needs, funny enough it matched the name of my script so here's the output: ``` # python fcgi_app.py ('404 Not Found', [('x-powered-by', 'PHP/5.3.21'), ('content-type', 'text/html')], '<html>\n\t<head>\n\t\t<title>test php</title>\n\t</head>\n<body>\nChecking</body>\n</html>', '') ``` And Here's the source Giving me the conclusion that this is in fact a PHP issue (even tho i've hated on lighttpd for not honoring the 200 code php should respond with.. And for that i'm sorry. Should go bash a little on PHP and see if that helps me come to a conclusion) Temporary Solution Placing the following in the top part of your .php page will work around this issue. Note that it's a clean workaround, it will work but it's not a long term fix for sure. ``` <?php header("HTTP/1.0 200 Found"); ?> ```