I'm feeling completely stupid because I've spent two hours solving task which should be very simple and which I solved many times before. But now I'm not even sure in which direction to dig.
I fail to fetch static content using ajax from local servers (Apache and Mongrel). I get responses 200 and 206 (depending on the server), empty response text (although Content-Length header is always correct), firebug shows request in red.
Javascript is very generic, I'm getting same results even here: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first (just change document location to 'http://localhost:3000/whatever') So, it's probably not the cause.
Well, now I'm out of ideas. I can also post http headers, if it'll help.
Thanks!
Response Headers
Connection close
Date Sat, 01 May 2010 21:05:23 GMT
Last-Modified 开发者_如何学C Sun, 18 Apr 2010 19:33:26 GMT
Content-Type text/html
Content-Length 7466
Request Headers
Host localhost:3000
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
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 115
Connection keep-alive
Referer http://www.w3schools.com/ajax/tryit_view.asp
Origin http://www.w3schools.com
Response Headers
Date Sat, 01 May 2010 21:54:59 GMT
Server Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 mod_jk/1.2.28
Etag "3d5cbdb-fb4-4819c460d4a40"
Accept-Ranges bytes
Content-Length 4020
Cache-Control max-age=7200, public, proxy-revalidate
Expires Sat, 01 May 2010 23:54:59 GMT
Content-Range bytes 0-4019/4020
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type application/javascript
Request Headers
Host localhost
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
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 115
Connection keep-alive
Origin null
UPDATED:
I've found a problem, it was about cross-domain requests. I knew that there are restrictions, but thought they're relaxed for local filesystem and local servers. (and expected more descriptive error message, anyway) Thanks everybody!It seems lake a caching problem only. Just delete cache inside of Internet Explorer and repeat your experiment. All HTTP GET requests will be cached. IE cache also ajax
responses. If you don't like it you can append the URL with the text like '?p=blala'. Where 'p' is a name which will be interpret as a name of a parameter and text 'blala' must be unique in every request. Typically one use (new Date).getTime()
construct to generate such 'blala'. IE will "think", that URL is new and will always send request to server.
UPDATED: Caching of static data will be made in all browsers, especially if Web server explicitly allow this: see Cache-Control: max-age=7200, public, proxy-revalidate
is the response from server. Just try to go to http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first and modify the line
xmlhttp.open("GET","ajax_info.txt",true);
to
xmlhttp.open("GET","ajax_info.txt?p=" + (new Date).getTime(),true);
then click on "Edit and Click Me >>". Then if you click on "Change Content" button you will see in the HTTP traffic full data contain. I don't see any time 206 code. What it means if Response has "Accept-Ranges: bytes
" and "Content-Range
" like "bytes 0-4019/4020
" inside of HTTP header you can read on http://benramsey.com/archives/206-partial-content-and-range-requests/
精彩评论