News

Good Design Practices: MVC Frameworks with Ajax

0

updating,getting,setting,deleting), without ever needing to reload the page or send the user to another for fetching or setting new content.

Sure, users should be led to the homepage after logging in, but it’s way better for an user to be able to click on a panel at the top, do his login, and continue his quest without having to wait for the page reloading. Always remember, user wants to be served right there, right at the moment, and he doesn’t have time neither the patience to wait for your non-modern website to update content. So get with the times, start using both Ajax and these news MVC frameworks, and design your application intuitively!

Combining Ajax with MVC Frameworks:

I guess you know the structure of work done in MVC:

model/

vote_model.php

poll_model.php

controller/

vote_controller.php

poll_controller.php

view/

vote_view.php

poll_view.php

The thing is, that everything goes from model, to controller, to view, and then goes from view, controller, back to model. It’s a whole game of get/set, just with more code readability, structure, and the good kind of complication. You organize your database abstraction code in you model’s, your presentation in views, and glue the both, with the controller, by having it make the both interact with each other.

But what does Ajax have to do with all this?

Simple. By combining both, you get a totally seamless application where the code is readable, ordered, structured and make it possible for the user to get his information, or give his opinions, on the same page, without having to reload at all.And that what’s makes moving to the cloud attractive, everything is simple, everything is seamless, and it gives the user his dose of informative drug right at the time.

Combining Ajax with Model / View / Controller Frameworks

Let’s take this piece of code for an example:

$.post('voter/get_concept_data',{concept_id: 1}).done(function(data) {

				$("#concept").html(""" + data + """);

			});
Here i have in my view, at the <script> tag, a jQuery selector which makes a POST call to my controller at get_concept_data method, in my Voter controller class, and when that controller gets the concept from the database, with the concept_id being 1, it returns that concept word it found using a method from the model to get the concept with the exact concept_id column, where jQuery puts it in the "data" argument of the closure (anonymous function) i made, that puts that concept word back to my view.

And all of this, with just a POST call, and i didn't even refresh the page to get another word.

So Ajax and MVC Makes it possible:
  • To load content seamlessly into the page without having to reload the page,
  • To create a loop of data getting and data setting,
  • Have the user log in, post comments, do polls, vote something, or do his work
  • Reinforce a stateless system where the user gets his data/ sets it without navigating around,
  •  Add a layer of security and input validation.

So use it, and use it wise!

Good Design Practices: Database Patterns

Previous article

Cars of the Future

Next article

You may also like

Comments

Leave a reply

Your email address will not be published. Required fields are marked *

More in News