Skip to content


jQuery 1.0.4 Released

John Resig over at jQuery has announced the release of jQuery 1.0.4 to the public! As usual, there are bug fixes...plus a bit more. His focus for this patch was adding improvements to jQuery's Ajax functionality. Below is a list of all the updates:

  • Tons of bug fixes (Full List)
  • Extensions to $.ajax(): $.ajax accepts additional options: beforeSend, async and processData; returns XMLHttpRequest to allow manual aborting of requests, see docs for details.

    Example: Add extra headers to an Ajax request using beforeSend

    JavaScript:
    1. $.ajax({
    2.   type: "POST",
    3.   url: "/files/add/",
    4.   beforeSend: function(xhr) {
    5.     xhr.setRequestHeader( "Content-type", "text/plain" );
    6.   },
    7.   data: "This is the contents of my text file."
    8. });

    Example: Perform a synchronous Ajax request.

    JavaScript:
    1. // Get the HTML of a web page and save it
    2. // to a variable (the browser will freeze until the
    3. // entire request is completed).
    4. var html = $.ajax({
    5.   type: "GET",
    6.   url: "test.html",
    7.   async: false
    8. }).responseText;
    9.  
    10. // Add the HTML into the page
    11. $("#list").html( html );

    Example: Sending a JavaScript object using processData.

    JavaScript:
    1. // The data to send to the server
    2. var params = {
    3.   name: "John",
    4.   city: "Boston"
    5. };
    6.  
    7. $.ajax({
    8.   type: "POST",
    9.   url: "/user/add/",
    10.   processData: params
    11. });

    Example: Aborting an Ajax request after a specific delay in time.

    JavaScript:
    1. // Perform a simple Ajax request
    2. var req = $.ajax({
    3.   type: "GET",
    4.   url: "/user/list/",
    5.   success: function(data) {
    6.     // Do something with the data...
    7.     // Then remove the request.
    8.     req = null;
    9.   }
    10. });
    11.  
    12. // Wait for 5 seconds
    13. setTimeout(function(){
    14.   // If the request is still running, abort it.
    15.   if ( req ) req.abort();
    16. }, 5000);

  • AJAX module: The public $.ajax API is now used internally (for $.get/$.post etc.); loading scripts works now much more reliably in all browsers (with the exception of Safari, which is a work in progress).
  • New global Ajax handler: ajaxSend - called before an Ajax request is sent.

    Example: Add extra headers to all Ajax requests using the ajaxSend event.

    JavaScript:
    1. $(document).ajaxSend(function(xhr){
    2.   xhr.setRequestHeader("X-Web-Request", "MySite.com");
    3. });

  • Extensions to global Ajax handlers: ajaxSend, ajaxSuccess, ajaxError and ajaxComplete get XMLHttpRequest and settings passed as arguments.

    Example: Prevent any POST requests that are sending too much data.

    JavaScript:
    1. $(document).ajaxSend(function(xhr,options){
    2.   if ( options.type == "POST" && options.data.length> 1024 )
    3.     xhr.abort();
    4. });

    Example: Show a special message for requests submitted using an Ajax POST.

    JavaScript:
    1. $("#dataSent").ajaxSend(function(xhr,options){
    2.   if ( options.type == "POST" )
    3.     $(this).show();
    4. });

  • Extensions to event handling: pageX and pageY are available in all browsers now. (IE does not provide native pageX/Y).

    Example: Have a tooltip follow a user’s mouse around the page.

    JavaScript:
    1. $(document).mousemove(function(e){
    2.   $("#mousetip").css({
    3.     top: e.pageY + "px",
    4.     left: e.pageX + "px"
    5.   });
    6. });

  • Improved docs: $(String) method has now two separate descriptions, one for selecting elements, one for creating html on-the-fly.
  • FX module: Most inline styles added by animations are now removed when the animation is complete, eg. height style when animating height (exception: display styles).

Posted in Blog, Technology.

Tagged with , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.