AJAX And MVC

In his documentation of the AJAX.NET wrapper, Michael Schwarz says: “It should be pointed out that technologies such as AJAX are very likely going to lead to violations of layered architectures (N-Tier). My opinion is that AJAX increases the likelihood that the presentation logic layer (or worse, the business layer) will leak into the presentation layer.”

I have been away camping for a little over a week, and I have been thinking that this does not have to be so. I have been imagining a framework where the browser contains JavaScript that responds to events that originate on the server. AJAX would be used not to send content per se, but to trigger updates – elements of the user interface would subscribe to data, and the update event would trigger a screen refresh.

Update events would be managed by a timer, and/or by user interactions such as button clicks. Developers would design user interfaces and bind elements to data, but the application on the server could still adhere to the MVC pattern. The controller would service requests, the data would be managed by a model and the view would generate the initial screen.

In any event, I do expect that there will be a lot of sloppy AJAX based code out there that mixes the business layer with the presenation layer. Hell, I just finished working on a project that did not use AJAX that had the same problem. I sometimes think that it is not that every coder is an idiot, but that every idiot seems to be writing code.

Still, before I get too snide, I have also noticed that even bad code can often serve a useful purpose. I recently revisited some code I wrote a while back and was very disappointed in my efforts to be clever – trying to be clever often isn’t.



Leave a Reply