Empty response body in ajax (or 206 partial content)
I feel completely stupid because I spent two hours solving a problem that should be very simple and which I have solved many times before. But now I'm not even sure which direction to dig.
I am unable to get static content using ajax from local servers (Apache and Mongrel). I get 200 and 206 responses (depending on the server), empty response text (although the Content-Length header is always correct), firebug shows the request in red.
Javascript is very generic, I get the same results even here: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first (just change the document location to http: // localhost: 3000 / whatever ') So, this is probably not the reason.
Okay, now I have no ideas. I can also post the http headers if that helps.
Thanks!
Response Headers
Connection close
Date Sat, 01 May 2010 21:05:23 GMT
Last-Modified 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 found the problem, it was about cross-domain requests. I knew there were limitations, but thought they were relaxed for local filesystem and local servers. (and expected more verbose error message anyway)
Thanks everyone!
a source to share
Seems to be a problem with lake caching. Just remove the cache inside Internet Explorer and repeat the experiment. All HTTP GET requests will be cached . IE cache is also responsible ajax
. If you don't like it, you can add a url with text like "? P = blala". Where "p" is the name that will be interpreted as the name of the parameter, and the text "blala" must be unique in every request. Usually a construct is used (new Date).getTime()
to create such a "blala". IE will "think" this URL is new and will always send a request to the server.
UPDATED . Static data caching will be done in all browsers, especially if the web server explicitly allows it: see Cache-Control: max-age=7200, public, proxy-revalidate
- the response from the server. Just try to go to http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first and change the line
xmlhttp.open("GET","ajax_info.txt",true);
to
xmlhttp.open("GET","ajax_info.txt?p=" + (new Date).getTime(),true);
then click "Edit and click me →". Then, if you click the Edit Content button, you will see the full HTTP traffic data. I don't see any code 206. What does it mean if the Response has " Accept-Ranges: bytes
" and " Content-Range
" like " bytes 0-4019/4020
" inside the HTTP header, you can read http://benramsey.com/archives/206-partial-content-and-range -requests /
a source to share