与squid和ajax的冲突

发布于 2024-07-09 09:44:50 字数 1436 浏览 12 评论 0原文

我有一位用户在我们网站上的 ajax 调用中遇到错误。

错误粘贴在下面。

他们在 FF3 Windows 中收到错误,但在 IE 中没有。

根据一些搜索,这个问题似乎通常是由客户端协议鱿鱼引起的(您会注意到在错误的末尾,提到了鱿鱼)。

我的ajax代码与此处使用的相同: http://www.w3schools.com/Ajax/ajax_browsers .asp

有什么想法吗?

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我恋#小黄人 2024-07-16 09:44:50

为自己节省一些时间并使用 jQuery。 它有 ajax 的抽象,适用于所有浏览器,而不仅仅是 Internet Explorer,也许还有 FF。 ;-) 我假设上面的代码很旧并且很长一段时间没有更新。

jQuery 中的一个简单的 ajax 调用如下:

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

如果您了解 HTTP 的基础知识,它也会有所帮助 - 例如,请求方法(PUTPOSTGETDELETEHEAD)等等。 您粘贴的错误意味着您的请求中缺少标头 Content-Length,并且大多数服务器(如果不是全部)希望在您发出 PUT时发送该标头>POST 因为这些被假定为“数据更改”(例如创建、更新)。

也许 IE 会为您添加标头,但 Firefox 显然不会。

jQuery 负责处理这一切。 ;)

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. ;)

秋心╮凉 2024-07-16 09:44:50

如果 FF 无法为您执行此操作,您可以在 XHR 对象上使用 .setRequestHeader() 来设置内容长度。

由于您要在 .send(content) 方法中发布数据,因此只需在其前面添加一个带有 content.length 的标头即可。

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.

日暮斜阳 2024-07-16 09:44:50

您应该与您的用户坐在一起,并将 Fiddler HTTP 跟踪工具放在中间。 然后您可以轻松比较 IE 和 FF3 发送的请求。

这样,差异所在以及导致问题的原因就应该显而易见。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文