jQuery AJAX 在 Firefox 中慢,在 IE 中快

发布于 2024-07-26 04:17:45 字数 1261 浏览 1 评论 0 原文

我使用 jQuery 发布到 ASP .NET Web 服务来实现自定义自动完成功能。 该代码运行良好,但在 FireFox 中速度很慢(无法使其运行速度超过 1 秒)。 IE 速度极快 - 运行良好。 我使用 Firebug 在 Firefox 中观看该帖子。

下面是服务代码:

<ScriptService(), _
WebService(Namespace:="http://tempuri.org/"), _
WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1), _
ToolboxItem(False)> _
Public Class TestWebSvc
  Inherits System.Web.Services.WebService

  <WebMethod(), _
  ScriptMethod(ResponseFormat:=Script.Services.ResponseFormat.Json, UseHttpGet:=True)> _
  Public Function GetAccounts(ByVal q As String) As Object

    'Code taken out for simplicity

    Return result

  End Function

End Class

以及 jQuery ajax 调用:

$.ajax({
    beforeSend: function (req) { req.setRequestHeader("Content-Type", "application/json"); },
    contentType: "application/json; charset=utf-8",
    type: "GET",
    url: "http://localhost/Suggest/TestWebSvc.asmx/GetAccounts",
    data: "q='" + element.val() + "'",
    dataType: "json",
    success: testWebSvcSuccess
  });

如您所见,我尝试使用 HTTP GET 动词,希望这样可以使调用更快。 因为它没有,所以如果可以的话我可能会将其切换回使用 POST。 现在我只关注为什么它在 IE 中超级快而在 Firefox 中超级慢。

版本:jQuery 1.3.2; 火狐浏览器 3.0.11; IE 8.0.6001.18783(64 位)

感谢您提供的任何见解。

I'm using jQuery to post to an ASP .NET Web Service to implement a custom auto-complete function. The code works great, except it's slow in FireFox (can't get it to go faster than 1 second). IE is blazing fast - works great. I watch the post in Firefox using Firebug.

Here's the service code:

<ScriptService(), _
WebService(Namespace:="http://tempuri.org/"), _
WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1), _
ToolboxItem(False)> _
Public Class TestWebSvc
  Inherits System.Web.Services.WebService

  <WebMethod(), _
  ScriptMethod(ResponseFormat:=Script.Services.ResponseFormat.Json, UseHttpGet:=True)> _
  Public Function GetAccounts(ByVal q As String) As Object

    'Code taken out for simplicity

    Return result

  End Function

End Class

And the jQuery ajax call:

$.ajax({
    beforeSend: function (req) { req.setRequestHeader("Content-Type", "application/json"); },
    contentType: "application/json; charset=utf-8",
    type: "GET",
    url: "http://localhost/Suggest/TestWebSvc.asmx/GetAccounts",
    data: "q='" + element.val() + "'",
    dataType: "json",
    success: testWebSvcSuccess
  });

As you can see, I've tried to use the HTTP GET verb instead in hopes that that would make the call faster. As it does not, I'll probably switch it back to using POST if I can. Right now I'm just focused on why it's super fast in IE and super slow in Firefox.

Versions: jQuery 1.3.2; Firefox 3.0.11; IE 8.0.6001.18783 (64-bit)

Thank you for any insight you can provide.

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

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

发布评论

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

评论(5

赴月观长安 2024-08-02 04:17:45

我知道我在这个问题上迟到了,但我不得不处理类似的情况。 事实证明,“问题”是使用 http://localhost 而不是 127.0.0.1

IE,使用任一 URL 都可以快速执行。 FF 在使用 IP 地址时速度很快,但在使用 localhost 时增加了 1 秒的延迟。

I know I'm late to the party for this question, but I just had to deal with a similar situation. Turns out the 'problem' was using http://localhost instead of 127.0.0.1

IE performed fast using either URL. FF was fast with using an IP address, but added a 1 second delay with using localhost.

一人独醉 2024-08-02 04:17:45

因此,我不再只是在 Visual Studio 中点击“运行”,而是在 IIS 中创建了一个应用程序并从那里访问该页面 - 现在它在 FireFox 和 IE 中都可以快速运行。 奇怪……我对此仍然有点警惕——我有一种感觉,这可能会在某个地方再次困扰我,但现在看来问题已经解决了。

So instead of just hitting "Run" in Visual Studio, I created an application in IIS and accessed the page from there - now it works fast in both FireFox and IE. Strange... I'm still a little wary about this - I have a feeling this might come back to haunt me somewhere, but for now it looks like the problem is resolved.

小ぇ时光︴ 2024-08-02 04:17:45

我敢打赌 IE 正在缓存它。 由于某种原因,IE 有点更具攻击性(旧帖子,但我仍然参见问题)当涉及到缓存时,这可能也不例外。 尝试运行一些健全性检查,看看它是否真的缓存了它。

I'll bet IE is caching it. For some reason, IE is a little more aggressive (old post but I still see the issue) when it comes to caching, and this is probably no exception. Try and run a couple of sanity checks to see if its' really caching it.

青衫负雪 2024-08-02 04:17:45

抱歉我也迟到了这个问题。 Cassini(VS Web 服务器)+ Firefox 已知任何服务器请求(不仅仅是 ajax/webservice 请求)的性能问题。 127.0.0.1 解决方案是一个修复 - 另一种是更改 firefox 中的设置:

http://blog.anofsinger.com/2007/08/firefox-slowness-with-cassini-vs-web.html

Sorry I too am late to this question. Cassini (VS Web Server) + Firefox have known performance issues for any server request (not just ajax/webservice requests). The 127.0.0.1 solution is one fix - another is to change a setting in firefox:

http://blog.anofsinger.com/2007/08/firefox-slowness-with-cassini-vs-web.html

梦幻的味道 2024-08-02 04:17:45

您使用 beforeSend: 有原因吗?

您可以将内容类型设置为一个选项,如下所示:

contentType: "application/json; charset=utf-8"

另外,为什么不将 Web 方法的 url 设置为相对或绝对呢? 我怀疑完整的 uri 会产生影响,但你永远不知道。

Is there a reason why you are using beforeSend: ?

You can just set the content type as an option, like so:

contentType: "application/json; charset=utf-8"

Also, why not make the url to the web method relative or absolute? I doubt the full uri would make a difference, but you never know.

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