jQuery AJAX 在 Firefox 中慢,在 IE 中快
我使用 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 位)
感谢您提供的任何见解。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道我在这个问题上迟到了,但我不得不处理类似的情况。 事实证明,“问题”是使用 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.
因此,我不再只是在 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.
我敢打赌 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.
抱歉我也迟到了这个问题。 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
您使用 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.