tags:

views:

849

answers:

3

I have a user who gets an error from ajax calls on our site.

The error is pasted below.

They get the error in FF3 Windows, but not IE.

Based on some searching it seems this issue is often caused by the client protocol squid (you'll notice at the end of the error, squid is mentioned).

My ajax code is the same used here: http://www.w3schools.com/Ajax/ajax_browsers.asp

Any ideas?

ERROR

The requested URL could not be retrieved

While trying to process the request:

POST /library/cart/cart_ajax.php?action=refreshCartWidget&qty=dontuse& HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729)

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: identity,gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300

Connection: Close
Referer: http://mydomain.com/library

Pragma: no-cache
Cache-Control: no-cache

The following error was encountered:

Invalid Request
Some aspect of the HTTP Request is invalid. Possible problems:

Missing or unknown request method
Missing URL
Missing HTTP Identifier (HTTP/1.0)
Request is too large
Content-Length missing for POST or PUT requests
Illegal character in hostname; underscores are not allowed
Your cache administrator is webmaster. 
Generated Wed, 12 Nov 2008 09:28:58 GMT by ipwal3.osi-tech.com (squid/2.6.STABLE17)
+3  A: 

Save yourself some time and use jQuery. It has an abstraction for ajax, which works in all browsers and not just Internet Explorer, and maybe FF. ;-) I am assuming that the code up there is old and didn't get an update in a long while.

A simple ajax call in jQuery is as follows:

$.post(
  '/the/url/to/post/to',
  { some: data },
  function(data) { alert(data); }
);

It also helps if you understand the basics of HTTP - for example, the request methods (PUT, POST, GET, DELETE, HEAD) and so on. The error you pasted means that the header Content-Length is missing with your request and most servers (if not all) expect it to be send when you issue PUT or POST because those are assumed to be "data changing" (e.g. create, update).

Maybe IE adds the header for you, but Firefox apparently doesn't.

jQuery takes care of all that. ;)

Till
Well, you need to specify Content-Length or use chunked transfer encoding with HTTP/1.1, I believe. Otherwise you can't use keep-alive, and apparently just specifying "Connection: close" isn't enough.But yes, all this has been taken care of so many times over in commodity libraries, so best to take advantage of that.
araqnid
+1  A: 

You can use .setRequestHeader() on your XHR-object to set a content-length if FF doesn't do it for you.

Since you're posting your data in the .send(content) method, just add a header before that with content.length.

jishi
A: 

You should sit together with your user and put the Fiddler HTTP tracing tool in between. Then you can easily compare the request being sent by IE and FF3.

This way it should become visible where the differences are and why they're causing problems.

mkoeller