简体   繁体   English

ASP.NET MVC中的jQuery vs MicrosoftAjax

[英]jQuery vs MicrosoftAjax in ASP.NET MVC

Under what circumstances would you use MicrosoftAjax over jQuery in an ASP.NET MVC application? 在什么情况下你会在ASP.NET MVC应用程序中使用MicrosoftAjax而不是jQuery?

According to Scott Cate in this podcast Object Oriented AJAX with Scott Cate MicrosoftAjax is good for sending and retrieving data to and from the server. 根据Scott Cate在这个与Scott Cate一起使用的面向对象的AJAX播客中 MicrosoftAjax适用于向服务器发送数据和从服务器检索数据。 And jQuery is good for manipulating your data via the DOM once it arrives at the client. jQuery一旦到达客户端就可以通过DOM操作数据。 Yet, with a simple form plugin for jQuery you can send and retrieve data with jQuery quite easily. 然而,使用简单的jQuery表单插件,您可以非常轻松地使用jQuery发送和检索数据。 Often with a single line of code. 通常只有一行代码。

So I'm wondering what the difference is between MicrosoftAjax and jQuery within ASP.NET MVC? 所以我想知道ASP.NET MVC中MicrosoftAjax和jQuery之间的区别是什么?

Go with jQuery - even Microsoft has seen the error of their ways. 使用jQuery - 即使微软已经看到了他们的方式的错误。 The next version of Visual Studio will include jQuery and support it with intellisense. Visual Studio的下一个版本将包含jQuery并使用intellisense支持它。 You're also entirely correct regarding the simple plugin. 关于这个简单的插件,你也完全正确。 MS Ajax, while sometimes easier to work with initially, is slow and bloated. MS Ajax虽然有时更容易使用,但速度慢且臃肿。

I have tried to use both more or less side by side. 我试图并排使用或多或少。

The builtin ajax helpers works fine. 内置的ajax助手工作正常。

But jquery has a smaller footprint and is more transparent in use. 但是jquery的占用空间更小,使用更透明。

And when using the ajax helpers I get immediate results but no sense of what goes on behind the scenes 当使用ajax助手时,我会立即获得结果但却无法了解幕后发生的事情

Besides If you have to bridge over into jquery in order to extend your ajax scenario, you might as well start there. 除此之外如果你必须桥接到jquery以扩展你的ajax场景,你也可以从那里开始。

jQuery is lighter-weight, easier to integrate into standard javascript functions, and has great community support. jQuery重量更轻,更易于集成到标准的javascript函数中,并且具有出色的社区支持。 MS Ajax is heavy, but I suspect they are rewriting everything AJAX. MS Ajax很重,但我怀疑他们正在重写所有AJAX。

Just be sure to use the jQuery.ajax function and not jQuery.get - its more verbose, but vital for error handling. 确保使用jQuery.ajax函数而不是jQuery.get - 它更详细,但对于错误处理至关重要。

Don't skimp on error handling code just because jQuery.get() is easier. 不要因为jQuery.get()更容易而吝啬错误处理代码。 It may work on your tests, but you need some kind of error handling for the many cases it wont work. 它可能适用于您的测试,但是对于许多无法正常工作的情况,您需要进行某种错误处理。

I'm really not sure why get doesn't have error handling, but here's a quote from the jQuery documentation for get: 我真的不确定为什么得到没有错误处理,但这里是来自jQuery文档的get:

This is an easy way to send a simple GET request to a server without having to use the more complex $.ajax function. 这是一种简单的方法,可以将简单的GET请求发送到服务器,而无需使用更复杂的$ .ajax函数。 It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code). 它允许指定一个回调函数,该函数将在请求完成时执行(并且仅当响应具有成功的响应代码时)。 If you need to have both error and success callbacks, you may want to use $.ajax. 如果您需要同时包含错误和成功回调,则可能需要使用$ .ajax。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM