Posted on 13th January 2009 — Ajax is made incredibly simple with jQuery. There’s a number of helper functions to get in to the nitty gritty of Ajax, but if you want something that’s quick and simple to get going with the .load function is the best place to start.

.load will pull a URL from your server and load it in to the selector you specify.

Update: It’s worth noting that as of jQuery 1.3, the load function can take a string instead of an object if so required.

Finally: Optimisation

It’s worth noting that every time the user presses a key, there’s an Ajax hit. We wouldn’t want to do this in a real situation, unless we knew our server could take the traffic.

We could run this code when the form is submitted (remember to cancel the browsers default action by return false) or we could use a delay trick to ignore a quick succession of key presses (which you can see in the Ajax to validate forms example).

You should follow me on Twitter hereI tweet about jQuery amongst the usual tweet-splurges!