I'm still confused about where JavaScript code sits in the MVC pattern when building a web application. I thought it worked like this.
Because JavaScript code is compiled in the browser I think of it as part of the View, but it's handling user inputs, making server requests based on those events and then returning the data to page, so would that also make in part of the Controller?
Also, what does it mean when they refer to the Domain Model in MVC?
JavaScript is going to be primarily a UI related concern; your view is making an ajax request to the controller. The controller isnt making an ajax request; nor is the model. For all intents and purposes, an ajax request isnt anything different than a normal request; it's just that the browser isnt hanging until your response is returned.
JavaScript also executes in the context of your client, outside the purview of your server, so it should go into the view.
MVC is just a pattern. JavaScript code itself can implement this pattern, so I don't think of it as fitting into some other portion of your server side framework's pattern. Check out Backbone for a good example of using MVC in JavaScript code.
You can model your JavaScript code off of similar concepts that you model your server side code with. The JavaScript code itself will get served up through the view of your server side application, but unless you're only adding eye candy with JavaScript code (which you're not) then the JavaScript code is really its own entity and doesn't necessarily fit into your server side MVC paradigm.
Try to separate the JavaScript code from anything server side. Just consider it an 'add on' that, if disabled in the browser, won't break your application from running. I just add some niceties to allow for better interaction, etc. How you actually model the JavaScript code is up to you, (but I do highly recommend Backbone)
One could also do a Rich frontend in javascript backed only by a data source. In this case, once again, javascript will be responsible for maintaining models, views and controllers.
Domain model generally just refers to the business logic of your application. The brains so to speak of what should actually happen in your app. It's kind of an abstract concept encapsulating all the business logic of an app.
Nick, my personal experience in MVC, working with Zend or Spring, I think JavaScript code would be considered as a part of the View since JavaScript code is helping View and is directly interacting with the view. Send and receive of data through Ajax can be considered as a request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With