The Control of jQuery with Ajax


As the web evolves, new technologies are emerging and uniting in remarkable ways. The combination of Ajax and jQuery, in particular, is one of the most powerful unions to date.

Ajax in Practice
Let’s say that you have a login form for your web application. To ensure that the provided login name and password entered by the user is a match without using Ajax, your web application would have to load a whole new web page that shows an account screen if the login was successful, or show an error screen if the login failed. This is the old way of handling logins.

The web server (usually through a server-side script/language such as PHP) takes the two parameters and then queries your user database to see if there is a match.
If there is a match found in your database, then the web server can return a success flag. Otherwise, the web server could return an error message.
Next, you would then have a JavaScript function that accepts the Ajax response. If the response is successful, it could use window.location to send the user to their account screen.

What is jQuery?
Released in January of 2006 jQuery is a cross-browser JavaScript library designed to simplify the client-side script of HTML.
Used by close to a million websites jQuery is the most popular JavaScript library in use to date.
jQuery makes it easy to handle DOM objects, events, effects and Ajax, automatically takes care of JavaScript leaks, and has countless third-party plugins.

The Problem with Ajax
Despite its revolutionary impact on the web, Ajax can be difficult to use even for veteran developers.  People will usually create their own custom functions to handle Ajax calls so that the functionality can be reused across a web application. This can become very tedious when a web application makes use of different types of Ajax calls — such as the ability to handle both synchronous and asynchronous calls — or the ability to handle different response formats such as string messages, HTML, CSV, XML, JSON, etc.

At the end of the day, the simple idea of creating a custom httpRequest() function quickly turns into a big project.
The other advantage of jQuery is that it has additional Ajax functions and methods that you can use, which can further reduce development and debugging time.


Hello Ajax. Meet jQuery.
Among other advantages, one of my favorite features of jQuery is its ability to leverage Ajax with very little effort. To make an Ajax call, you can do something like this:
$.Ajax({
  type: "POST",
  url: "some.php",
  data: "name=John&location=Boston",
  success: function(msg){
    alert( "Data Saved: " + msg );
  }
});
If you’ve developed Ajax applications before without jQuery, you’ll immediately see the value here. jQuery has put all of the properties of Ajax into one simple API. You can control everything including the url, cache, success function, data type, and even synchronization, all from one neat declaration. It’s nothing short of beautiful.


If you’re not using a JavaScript Web Development framework like jQuery or MooTools yet, and you’re planning on creating responsive web applications, you should leverage these awesome libraries.

No comments:

More Like This

Related Posts Plugin for WordPress, Blogger...

AddThis