ASP.NET MVC 和 Ajax 慢?

发布于 2024-09-14 07:30:19 字数 585 浏览 2 评论 0原文

我刚刚开始尝试 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 技术交流群。

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

发布评论

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

评论(2

陌上青苔 2024-09-21 07:30:19

使用 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.

红墙和绿瓦 2024-09-21 07:30:19

我认为您有点误解了。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

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