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 โโ;-))
source share