ASP.NET MVC 和 Ajax 慢?
我刚刚开始尝试 MVC 2 和 Ajax,我想知道我是否做错了什么,因为我的印象是 Ajax 会非常快地在网页中进行更改。我的例子是 Ajax actionlink:
<div>
<%: Ajax.ActionLink("Dita", "AjaxView", new AjaxOptions { UpdateTargetId = "myDiv" })%>
</div>
<div id="myDiv">
Change this text</div>
和 Action 方法:
public ActionResult AjaxView(string id)
{
return Content("Text changed!"); ;
}
这是一个相当短的简单文本字符串,仍然需要大约 1-2 秒才能显示文本。也许ajax不应该做我想象的那样,但我想我可以用它来即时预览文本和图像,有点像翻转功能(顺便说一句,我想知道是否可以将actionlink设置为调用鼠标悬停而不是单击时的操作方法?)
这么慢是正常的还是我错过了什么?
I've just started out trying MVC 2 and Ajax, and I'm wondering if I'm doing something wrong, because I was under the impression that Ajax would make changes in a webpage very fast. The example I have is with the Ajax actionlink:
<div>
<%: Ajax.ActionLink("Dita", "AjaxView", new AjaxOptions { UpdateTargetId = "myDiv" })%>
</div>
<div id="myDiv">
Change this text</div>
And the Action method:
public ActionResult AjaxView(string id)
{
return Content("Text changed!"); ;
}
This is a rather short simple text string, and still it takes about 1-2 seconds before the text shows up. Maybe ajax isn't supposed to do what I thought it would, but I was thinking I could use it for instant previews of text and images sort of like a rollover function (by the way I was wondering if the actionlink can be set to invoke the action method on mouseover rather than click?)
Is it normal that it is this slow or am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
localhost
时,FF 和 Chrome 可能存在 IPv6 DNS 解析问题。此处描述的修复:Firefox 和Chrome 在本地主机上运行缓慢;已知修复不适用于 Windows 7
和此处
https://superuser.com/questions/174715/is-there-a-way-to-disable-ipv6-in-googles-chrome
我会先在 IE 和 Opera 中尝试检查是否可以工作速度更快。
注意:如果这确实是问题所在,那么这与 AJAX 无关。
It might be an IPv6 DNS resolution issue with FF and Chrome when working with
localhost
. Fixes described here:Firefox and Chrome slow on localhost; known fix doesn't work on Windows 7
and here
https://superuser.com/questions/174715/is-there-a-way-to-disable-ipv6-in-googles-chrome
I would try in IE and Opera first to check if it works faster.
Note: if that's actually the problem, this has nothing to do with AJAX.
我认为您有点误解了。AJAX 并不必然会使您的 Web 应用程序更快。 AJAX 的作用是仅加载您需要的信息,而不是重新加载整个页面。这样您就可以对正在查看的页面进行细微更改,而无需刷新整个页面。
要点是 - 当您调用 AjaxView 时,它仍然需要回调服务器,无论您做什么,这都需要时间。此动作缓慢的原因可能取决于不同的因素;
- 您的服务器可能正忙于做其他事情,因此消耗资源
- 您刚刚构建了程序集,使得第一次调用速度变慢
I think you've misunderstood slightly.. There is nothing about AJAX that will necessarily make your Web application faster. What AJAX does is to only load the information you need instead of loading the entire page over again. That way you can make subtle changes to the page you're viewing without having to refresh the entire page.
The point being - when you call AjaxView it still has to do a call back to the server which will take time no matter what you do. The reason why this action is slow might rely on different factors;
- Your server might be busy doing something else, hence consuming resources
- You just built the assembly, making the call slower the first time around