How are the concepts of MVC and AJAX related?

I am currently developing web applications after ten years of developing desktop systems, and I am trying to get an idea of โ€‹โ€‹the many concepts that I am studying. The last two concepts that I read are MVC (specifically ASP.NET MVC) and AJAX. I understand that MVC is a template used to separate logic and data, and AJAX is a combination of various web technologies for creating asynchronous and dynamic web pages.

  • How are these two connected?
  • Can or should you use two together?
  • If so, can you give some simple examples?

I apologize if these are weird questions, and I'm comparing apples to oranges, forgive me, because I'm still a huge giant noob.

+4
source share
3 answers

Ajax is just a way to request data: usually with Ajax, instead of requesting a full HTML web page, you simply request:

  • or part of the page (for example, the HTML code of one part of the screen that you want to refresh without reloading the entire page)
  • or some data; using JSON or XML as a data exchange format, for example

MVC describes the stacks used for:

  • Access to data and execution of actions / calculations / regardless of them (M)
  • Introduce It (V)
  • Passing through a controller that determines which model and view should be used to service the requested data.

When you use an Ajax request, you do exactly the same as for the full page:

  • get a request
  • determine which model and method should be called
  • name them (maybe they will do something with the database or something else that they need)
  • pass data to a view that displays it

Two differences:

  • A โ€œviewโ€ in one case displays a full HTML page: in another case, only part of it or some JSON / XML format
  • In one case, the request is usually executed asynchronously

Ajax or not, you can use MVC ... or not!
If you use MVC for a request other than Ajax, then why not do it for Ajax requests too?

Sorry, I wonโ€™t give you any example code - Iโ€™m not a .NET developer, so I wonโ€™t be able to handle it (but the concept is the same in other languages โ€‹โ€‹;-))

+6
source

I'll bite ...

  • They are not connected by anything other than web concepts. Ajax is a method of making an HTTP request and processing the result. MVC is the architectural model for building your web application.

  • Yes. No matter what architecture you use for your web applications, you should use Ajax where it makes sense. Ajax can improve the performance of your application and improve the user interface and user interface by eliminating bloated data transfer and screen flicker / refresh.

  • You can easily use Ajax through a number of javascript frameworks such as jQuery . Just download and include the .js framework files in your application, access it from your html and read the documentation on how to make Ajax requests.

+4
source

How are they connected?

I assume you are taking this from the ASP.NET developer POV.

This is really simple because simple Ajax (+ JSON) works much better with ASP.NET MVC than ASP.NET web forms. Due to the way ASP.NET Webforms mix together with the view and the controller (not to mention the fact that Postback and ViewState are its crutch so that pre-Ajax pages can overcome web statelessness), it was very difficult initially.

The ASP.NET site management method cannot be directly (or at least easily accessible) from Javascript, it practically does not allow using regular Ajax until ASP.NET Ajax UpdatePanels appear (which was, IMHO, another crutch )

With the advent of ASP.NET MVC, it is now much easier to use direct Ajax and JSON libraries for ASP.NET web applications.

+2
source

All Articles