Super Simple Ajax (Without a Framework)

Published Friday 12th of June 2009

If you're looking for the bare minimum when it comes to doing cross-browser GET or POST XHR then this might be the script for you.

I know there's hundreds (probably thousands) of these scripts out there already but even the most lightweight ones I could find seemed kind of bloated.

Example

// GET latest-comments.php and update the #latest-comments element
superSimpleAjax({url'latest-comments.php'}, 'latest-comments');

// GET article with ID 12 and alert its contents
superSimpleAjax({
    
url:        'get-article.php'
    
data:        'id=12'
    
callback:    function (data) {
        
alert(data);
    }
});

// POST a comment to post-comment.php
superSimpleAjax({
    
method:        'POST'
    
url:        'post-comment.php'
    
data:        'author=John Doe&email=johndoe@johndoe.com&content=Hi, my name is John Doe'
    
callback:    function (data) {
        
alert('Thanks for your comment!');
    }
});

Grab the code from Google Code. It's about 1k uncompressed.

Enjoy!

Tags
Comments
No comments

Bookmark this Article

  • del.icio.us
  • Digg
  • Furl
  • Google
  • Technorati
  • Ma.gnolia
  • Blinklist
  • Blogmarks
  • Rojo
  • Stumbleupon

Comments Closed

Comments for this article are closed.

Random jQuery Plug-ins

  • Live Validation

    Use this plug-in to add live validation to any form on your page. The plug-in indicates whether a form control is valid or not by switching between an...

    Details

  • Static to Dynamic Google Map

    This plug-in turns a static google map into a dynamic one by inspecting the attributes passed to the static map API. It's still in beta and doesn't su...

    Details

  • Togglable DL

    Use this plug-in on your definition-lists (dl-elements) to allow the dd:s for a dt to be toggled when clicking the dt. Don't use it unless it's semant...

    Details

More Plug-ins

Recent Comments

  1. Andreas on "SleekPHP User Handling"

    Thank you for showing interest :) Were the docs en...

  2. ciptard on "SleekPHP User Handling"

    Ok, thank you

  3. Andreas on "SleekPHP User Handling"

    I might write a "getting started" article for Slee...

Page cached. Loaded in: 0.0105 second(s).
Last DB change: 2012-02-04 08:04:40
Last file change: 2011-10-03 07:42:35
Cache created: 2012-02-04 10:02:18