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

No Comments

No comments yet, why not be the first to post one?

Post a Comment

Random jQuery Plug-ins

  • Max Length Form Controls

    Gives form-controls with a 'maxlength-XXX'-class a max-length and prohibits user from entering more than set amount. It also displays number of charac...

    Details

  • Tag Sizes

    Use this plug-in on a list of tags (li:s) and it will use whatever numbers found in the list to give each tag a corresponding size.

    Details

  • Ajax Loader

    Use this plug-in when you want to inform your visitors that a certain part of your page is currently loading. The plug-in adds a faded 'loading-div' o...

    Details

More Plug-ins

Recent Comments

  1. AL on "Accessible, Stylish Modal Windows With Modern CSS"

    @Matt - What exactly isn't working? "Not working" ...

  2. roboteich on "Accessible, Stylish Modal Windows With Modern CSS"

    This is hardly accessible. Screen reader focus is...

  3. Matt on "Accessible, Stylish Modal Windows With Modern CSS"

    I have tried to implement this, but for some reaso...

Page cached. Loaded in: 0.0244 second(s).
Last DB change: 2010-09-03 17:14:49
Last file change: 2010-08-12 15:31:16
Cache created: 2010-09-07 15:43:17