Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery MVC architecture

what is the best way to create MVC architecture in jQuery?

Should I use jQuery.extend()?

jQuery.extend({
  View: function(){}
});

...or jQuery Plugin?

(function($) {

  $.fn.model = function() { return this; }; 

})(jQuery);

...or just objects in JavaScript?

var model = {}
var view = {}
var controller = {}

Thank you!

like image 569
Tomas Barbak Avatar asked Apr 16 '10 17:04

Tomas Barbak


People also ask

What is MVC in jQuery?

Building Web Applications with ASP.NET Core 3 MVCThe MVC Framework contains built-in support for unobtrusive Ajax. You can use the helper methods to define your Ajax features without adding a code throughout all the views. This feature in MVC is based on the jQuery features.

What is MVC architecture in JavaScript?

MVC stands for Model-View-Controller. It's a design pattern that breaks an application into three parts: the data (Model), the presentation of that data to the user (View), and the actions taken on any user interaction (Controller).

Why Ajax is used in MVC?

It is a client-side script that communicates to and from a server/database without the need for a postback or a complete page refresh. The Ajax speeds up response time. In other words, Ajax is the method of exchanging data with a server, and updating parts of a web page, without reloading the entire page.

Does JavaScript use MVC?

js is a JavaScript framework that implements the MVC architecture. Events/input from the View is sent to the Controller where they're processed and data sent to the Model.


1 Answers

Just use objects in javascript. The view can contain all the knowledge of things like jquery and other UI concerns, while the controller/model can deal with other logic and communication with the server (assuming ajax). I wrote a blog post about this:

MVC Pattern with Javascript

like image 94
Joel Martinez Avatar answered Sep 17 '22 07:09

Joel Martinez