Hi Alex, hi everybody,
congratulations to your article about realising the MVC- pattern with JavaScript, it was (and still is) very interesting, especially with the dojotoolkit.
I have a short question and hope I can find help here.
I try to create an architecture with PHP and dojo, where I´ve a MVC at the server- side and the client- side, too. The only thing the server does is to create JSON from the desired data. With dojo.xhrPost the data will come to the client MVC. At this point I´m not sure, should the AJAX- call be a part of the model or a part of the controller?
I prefer the solution with the model, but i´ve found same articles with outher technologies, that using the controller for the AJAX- call. So, what do you think is the better way?
Thanks for helping and useful hints,
hava a nice day
masiru
AJAX calls in controller
Hi, Masiru!
Generally, I think that ajax calls should be in a contoller. Thus controller modifies model on particular event (page load or user input) and view changes itself according to model. This because I prefer "passive" models, when model only stores information and notifies subscribers about changes in its state and does not contain self-initalization code.
Sincerely,
Alex
RE: AJAX calls in Controller
Hi Alex,
thank you for your answer. I think the ajax calls in the controller is a good decision.
Have a nice time,
sincerely,
masiru
RE: AJAX calls in Controller
Hi everyone, hi Alex,
I´m not sure wheter to do the AJAX- request in the controller is a good idea, because there are major problems by delegating the received data to the Model based on the asynchronous characteristic of the request. The data no longer exists when i call the Models methods. I don´t know a solution for this problem. On the othe side, when the request is done by the model, this problem doesn´t exist. Every time when I need data from the server I do a new request.
Does everybody know a way the realise the request in the controller? Or any other best practise for AJAX- calls with the MVC pattern?
Sincerely,
masiru