SlideShare a Scribd company logo
jQuery: Events, Animation, Ajax
jQuery Events: .one()




// event will be handled only once
$("#do").one("click", function () {
    alert("Done!");
    $(this).text("Can't do it :(");
});


                        http://jsfiddle.net/jsfiddlr/CCr5T/
jQuery Events: .bind()




// one handler for multiple events
$("#field").bind("focus blur", function() {
    $(this).toggleClass("active");
});




                           http://jsfiddle.net/jsfiddlr/gE2dk/
jQuery Events: .bind()



  // multiple handlers per call
  $("#field").bind({
      click: function () {
          $("#echo").empty();
      },
      keyup: function () {
          $("#echo").text($(this).val());
      }
  });

                            http://jsfiddle.net/jsfiddlr/U7jF9/
jQuery Events: .live()


// event will be handled only within context
$("p", $("#c2")[0]).live("click", function () {
    alert("P");
});

// document-wide handling
$("p.alt").live("click", function () {
    alert("P.ALT");
});


                              http://jsfiddle.net/jsfiddlr/bruQc/
jQuery Events: .trigger()


// triggers custom event with parameters
$("#edit").click (function () {
    var text = $("#text");
    var original = text.text();
    text.text("Some another text.");
    text.trigger("edited", [original, 10]);
});

// handles custom event with parameters
$("#text").bind("edited", function (event, original, revision) {
    alert(original + " (rev: " + revision + ")");
});

                                        http://jsfiddle.net/jsfiddlr/vw5E8/
jQuery Events: event.result



// returns custom result
$("h1").click(function () {
    return 10;
});

// uses custom result returned by previous handler
$("h1, h2").click(function (event) {
    alert(event.result);
});




                                http://jsfiddle.net/jsfiddlr/CnFY9/
jQuery Events: .remove()/.detach()

   // removes first para and detaches second
   // then appends them back to body
   $("#do").click(function () {
       // handlers are removed too
       p1.remove();
       // handlers are kept untouched
       p2.detach();

         $("body").append(p1).append(p2);
   });

   p1.click(function () { alert("First"); });
   p2.click(function () { alert("Second"); });

                                  http://jsfiddle.net/jsfiddlr/Yq9pM/
jQuery Events: namespaces
   // just another one ordinary handler
   text.click(function () { alert("?"); });

   // namespaced event handler
   text.bind("click.me", function () {
       // will be fired on "click" and "click.me"
       alert("I am!");
   });

   // multiple namespaced events handler
   // (not nested, but multiple namespaces)
   text.bind("click.me.you", function () {
       // will be fired on "click", "click.me" and/or "click.you"
       alert("I am! You are too!");
   });

   // another handler of couple of namespaced events
   text.bind("mouseover.me mouseout.me",function() {
       $(this).toggleClass("active");
   });
                                           http://jsfiddle.net/jsfiddlr/4L3Fc/
jQuery Events: namespaces
 // triggers non-namespaced event only
 $("#click").click(function () { text.trigger("click!"); });

 // triggers namespaced event
 $("#click-me").click(function () { text.trigger("click.me"); });

 // triggers namespaced event
 $("#click-you").click(function () { text.trigger("click.you"); });

 // unbinds certain event in certain namespace
 $("#unbind-click-me").click(function () {
     // profit? delete only certain handlers, not all
     text.unbind("click.me");
 });

 // unbinds all events in certain namespace
 $("#unbind-me").click(function () {
     // or all namespace members
     text.unbind(".me");
 });                                        http://jsfiddle.net/jsfiddlr/4L3Fc/
jQuery Animation: .stop()
    // drawback is that if user opens/closes "A"
    // there will be no effect
    // until previous animation finished

    $("#open-a").click(function () {
        $("#a").animate({
            height: "80px"
        }, 2000, "linear");
    });

    $("#close-a").click(function () {
        $("#a").animate({
            height: "0"
        }, 2000, "linear");
    });
                                       http://jsfiddle.net/jsfiddlr/48uEK/
jQuery Animation: .stop()
  // here is solution demonstrating .stop()
  // and certain easing (currently "swing")

  $("#open-b").click(function () {
      $("#b").stop(true, true).animate({
          height: "80px"
      }, duration, easing);
  });

  $("#close-b").click(function () {
      $("#b").stop(true, false).animate({
          height: "0"
      }, duration, easing);
  });                            http://jsfiddle.net/jsfiddlr/48uEK/
jQuery Animation: .stop()


// another solution (maybe more appropriate),
// but example wasn't about this

$("#open-a, #close-a").click(function () {
    var div = $("#a");
    if (div.is(":animated")) {
        return;
    }
    div[div.is(":visible") ? "fadeOut" :"fadeIn"](duration);
});




                                     http://jsfiddle.net/jsfiddlr/48uEK/
jQuery Animation: .queue()


  // intention: smoothly show element
  // and then remove it from the DOM
  $("#b1").click(function () {

        // element gets removed before
        // animation finishes
        $("#a")
            .fadeIn(duration)
            .remove();

  });
                             http://jsfiddle.net/jsfiddlr/EXNj9/
jQuery Animation: .queue()

// solution: use animation queue
$("#b2").click(function () {

   $("#b")
       .fadeIn(duration)
       .queue(function(next) {
           $(this).remove();
           // common pattern is to enable execution of
           // other animations (added after .queue() call)
           // by calling the next one
           // (in our example we could omit this)
           next();
       });

                                    http://jsfiddle.net/jsfiddlr/EXNj9/
jQuery Ajax: .ajaxStart()
$(this)

          // show spinner at ajax start
          .ajaxStart(function() {
              $(this).html(
              $("#spinner").clone().show());
          })

          // load content via ajax
          // when loaded it will replace spinner
          .load("/echo/html/", {
              html: "<h1>I've just loaded!</h1>",
              delay: 3
          });
                                  http://jsfiddle.net/jsfiddlr/t38Rx/
jQuery Ajax: .ajaxPrefilter()




// if URL contains "some" then fake request will be executed
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
    if (options.url.indexOf("some") >= 0) {
        options.dataTypes = ["fake"];
    }
});




                                     http://jsfiddle.net/jsfiddlr/VB9ur/
jQuery Ajax: .ajaxTransport()
 // setting transport for "fake" request
 $.ajaxTransport("fake", function(options, originalOptions, jqXHR) {

    // if previous request with certain URL is finished
    // then process this one
    if (urls.indexOf(options.url) === -1) {

        urls += options.url;
        return {
            send: function(headers, completeCallback) {
                setTimeout(function() {
                    urls = urls.replace(options.url, "");
                    completeCallback(200, "success", {
                        "fake": "Success!"
                    });
                }, 5000);
            },
            abort: function () {
            }
        };                                  http://jsfiddle.net/jsfiddlr/VB9ur/
jQuery Ajax: .ajaxTransport()


// otherwise alert error and send "server error" code
    } else {

       alert("Can't call same URL while waiting for response!" );
       return {
           send: function (headers, completeCallback) {
               completeCallback(500, "error");
           },
           abort: function () {
           }
       };

   }

                                         http://jsfiddle.net/jsfiddlr/VB9ur/
Thanks!




                  Thanks for attention and patience! 




                                                 constantin.titarenko@binary-studio.com
                                                     constantin.titarenko@gmail.com
October 4, 2011                                    http://about.me/constantin.titarenko
business, evolved.

More Related Content

What's hot (20)

PPT
jQuery 1.7 Events
dmethvin
 
PDF
DrupalCon jQuery
Nathan Smith
 
PPTX
Taming that client side mess with Backbone.js
Jarod Ferguson
 
PDF
An Introduction to Jquery
Phil Reither
 
PDF
Building Large jQuery Applications
Rebecca Murphey
 
PDF
Mulberry: A Mobile App Development Toolkit
Rebecca Murphey
 
PDF
A New Baseline for Front-End Devs
Rebecca Murphey
 
PPTX
IndexedDB - Querying and Performance
Parashuram N
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
Robert Nyman
 
ZIP
YUI 3
Dav Glass
 
PDF
Functionality Focused Code Organization
Rebecca Murphey
 
KEY
Advanced jQuery
sergioafp
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
PDF
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Robert Nyman
 
PDF
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
Robert Nyman
 
PDF
Dojo Confessions
Rebecca Murphey
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 
PDF
The Spirit of Testing
Marco Cedaro
 
PDF
YUI on the go
Christian Heilmann
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
Robert Nyman
 
jQuery 1.7 Events
dmethvin
 
DrupalCon jQuery
Nathan Smith
 
Taming that client side mess with Backbone.js
Jarod Ferguson
 
An Introduction to Jquery
Phil Reither
 
Building Large jQuery Applications
Rebecca Murphey
 
Mulberry: A Mobile App Development Toolkit
Rebecca Murphey
 
A New Baseline for Front-End Devs
Rebecca Murphey
 
IndexedDB - Querying and Performance
Parashuram N
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
Robert Nyman
 
YUI 3
Dav Glass
 
Functionality Focused Code Organization
Rebecca Murphey
 
Advanced jQuery
sergioafp
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Robert Nyman
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
Robert Nyman
 
Dojo Confessions
Rebecca Murphey
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 
The Spirit of Testing
Marco Cedaro
 
YUI on the go
Christian Heilmann
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
Robert Nyman
 

Viewers also liked (20)

PDF
Jst part1
Rendy Ardiwinata
 
PPT
The Power of BIG OER
Patrick McAndrew
 
PDF
Browsers with Wings
Remy Sharp
 
PPTX
Dispositivos de entrada
patiluki
 
DOCX
Class 2 unit 8 can you help me please
ridahprasetio
 
PDF
II Kongres eHandlu: Piotr Chmielewski, Social Media Now - "Kampanie reklamowe...
ecommerce poland expo
 
PPT
Compass Fi Treasury Pp July2008
ntrung
 
PDF
Memuary Tetrad 1
Denis Golikov
 
PDF
Program book 2013
otakuthon
 
PDF
Jeffrey Sachs
rosiem7
 
PDF
Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010
School Vegetable Gardening - Victory Gardens
 
PDF
Better Biz Dev – Music Startup Academy Denver - October 8, 2015
Shawn Yeager
 
PPSX
Chance challenge change Arise Roby
Arise Roby
 
PPT
Presentations tips
rioulrich
 
DOCX
Concumer behavior
shaikirfanbasha
 
PDF
Rtp 83 permentan ot.140 6 2014
Rhiana Rhiana
 
PPT
SE3221 - Playing the Glong Yao
rememberramc
 
PPT
2008111807581919
psy101618
 
PPT
Technological applications and innovations
rbulalakaw
 
DOCX
Saran makalah kb
Operator Warnet Vast Raha
 
Jst part1
Rendy Ardiwinata
 
The Power of BIG OER
Patrick McAndrew
 
Browsers with Wings
Remy Sharp
 
Dispositivos de entrada
patiluki
 
Class 2 unit 8 can you help me please
ridahprasetio
 
II Kongres eHandlu: Piotr Chmielewski, Social Media Now - "Kampanie reklamowe...
ecommerce poland expo
 
Compass Fi Treasury Pp July2008
ntrung
 
Memuary Tetrad 1
Denis Golikov
 
Program book 2013
otakuthon
 
Jeffrey Sachs
rosiem7
 
Groasis Waterboxx - Popular Science Winner of Best of What's New in 2010
School Vegetable Gardening - Victory Gardens
 
Better Biz Dev – Music Startup Academy Denver - October 8, 2015
Shawn Yeager
 
Chance challenge change Arise Roby
Arise Roby
 
Presentations tips
rioulrich
 
Concumer behavior
shaikirfanbasha
 
Rtp 83 permentan ot.140 6 2014
Rhiana Rhiana
 
SE3221 - Playing the Glong Yao
rememberramc
 
2008111807581919
psy101618
 
Technological applications and innovations
rbulalakaw
 
Saran makalah kb
Operator Warnet Vast Raha
 
Ad

Similar to jQuery: Events, Animation, Ajax (20)

PDF
jQuery secrets
Bastian Feder
 
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
PDF
Modular and Event-Driven JavaScript
Eduardo Shiota Yasuda
 
PDF
The Beauty of Java Script
Michael Girouard
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
PDF
Javascript Frameworks for Joomla
Luke Summerfield
 
KEY
amsterdamjs - jQuery 1.5
mennovanslooten
 
PDF
jQuery secrets
Bastian Feder
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PDF
jQuery: out with the old, in with the new
Remy Sharp
 
PDF
What's new in jQuery 1.5
Martin Kleppe
 
PDF
Writing Maintainable JavaScript
Andrew Dupont
 
PDF
The Open Web and what it means
Robert Nyman
 
PDF
Clean Javascript
Ryunosuke SATO
 
PDF
Virtual Madness @ Etsy
Nishan Subedi
 
PDF
jQuery
Ivano Malavolta
 
KEY
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
PDF
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
PDF
Frontin like-a-backer
Frank de Jonge
 
jQuery secrets
Bastian Feder
 
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Modular and Event-Driven JavaScript
Eduardo Shiota Yasuda
 
The Beauty of Java Script
Michael Girouard
 
The Beauty Of Java Script V5a
rajivmordani
 
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Javascript Frameworks for Joomla
Luke Summerfield
 
amsterdamjs - jQuery 1.5
mennovanslooten
 
jQuery secrets
Bastian Feder
 
Week 4 - jQuery + Ajax
baygross
 
jQuery: out with the old, in with the new
Remy Sharp
 
What's new in jQuery 1.5
Martin Kleppe
 
Writing Maintainable JavaScript
Andrew Dupont
 
The Open Web and what it means
Robert Nyman
 
Clean Javascript
Ryunosuke SATO
 
Virtual Madness @ Etsy
Nishan Subedi
 
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Frontin like-a-backer
Frank de Jonge
 
Ad

Recently uploaded (20)

PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PPTX
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
epi editorial commitee meeting presentation
MIPLM
 
Introduction presentation of the patentbutler tool
MIPLM
 
infertility, types,causes, impact, and management
Ritu480198
 
Difference between write and update in odoo 18
Celine George
 
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
Horarios de distribución de agua en julio
pegazohn1978
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 

jQuery: Events, Animation, Ajax

  • 2. jQuery Events: .one() // event will be handled only once $("#do").one("click", function () { alert("Done!"); $(this).text("Can't do it :("); }); http://jsfiddle.net/jsfiddlr/CCr5T/
  • 3. jQuery Events: .bind() // one handler for multiple events $("#field").bind("focus blur", function() { $(this).toggleClass("active"); }); http://jsfiddle.net/jsfiddlr/gE2dk/
  • 4. jQuery Events: .bind() // multiple handlers per call $("#field").bind({ click: function () { $("#echo").empty(); }, keyup: function () { $("#echo").text($(this).val()); } }); http://jsfiddle.net/jsfiddlr/U7jF9/
  • 5. jQuery Events: .live() // event will be handled only within context $("p", $("#c2")[0]).live("click", function () { alert("P"); }); // document-wide handling $("p.alt").live("click", function () { alert("P.ALT"); }); http://jsfiddle.net/jsfiddlr/bruQc/
  • 6. jQuery Events: .trigger() // triggers custom event with parameters $("#edit").click (function () { var text = $("#text"); var original = text.text(); text.text("Some another text."); text.trigger("edited", [original, 10]); }); // handles custom event with parameters $("#text").bind("edited", function (event, original, revision) { alert(original + " (rev: " + revision + ")"); }); http://jsfiddle.net/jsfiddlr/vw5E8/
  • 7. jQuery Events: event.result // returns custom result $("h1").click(function () { return 10; }); // uses custom result returned by previous handler $("h1, h2").click(function (event) { alert(event.result); }); http://jsfiddle.net/jsfiddlr/CnFY9/
  • 8. jQuery Events: .remove()/.detach() // removes first para and detaches second // then appends them back to body $("#do").click(function () { // handlers are removed too p1.remove(); // handlers are kept untouched p2.detach(); $("body").append(p1).append(p2); }); p1.click(function () { alert("First"); }); p2.click(function () { alert("Second"); }); http://jsfiddle.net/jsfiddlr/Yq9pM/
  • 9. jQuery Events: namespaces // just another one ordinary handler text.click(function () { alert("?"); }); // namespaced event handler text.bind("click.me", function () { // will be fired on "click" and "click.me" alert("I am!"); }); // multiple namespaced events handler // (not nested, but multiple namespaces) text.bind("click.me.you", function () { // will be fired on "click", "click.me" and/or "click.you" alert("I am! You are too!"); }); // another handler of couple of namespaced events text.bind("mouseover.me mouseout.me",function() { $(this).toggleClass("active"); }); http://jsfiddle.net/jsfiddlr/4L3Fc/
  • 10. jQuery Events: namespaces // triggers non-namespaced event only $("#click").click(function () { text.trigger("click!"); }); // triggers namespaced event $("#click-me").click(function () { text.trigger("click.me"); }); // triggers namespaced event $("#click-you").click(function () { text.trigger("click.you"); }); // unbinds certain event in certain namespace $("#unbind-click-me").click(function () { // profit? delete only certain handlers, not all text.unbind("click.me"); }); // unbinds all events in certain namespace $("#unbind-me").click(function () { // or all namespace members text.unbind(".me"); }); http://jsfiddle.net/jsfiddlr/4L3Fc/
  • 11. jQuery Animation: .stop() // drawback is that if user opens/closes "A" // there will be no effect // until previous animation finished $("#open-a").click(function () { $("#a").animate({ height: "80px" }, 2000, "linear"); }); $("#close-a").click(function () { $("#a").animate({ height: "0" }, 2000, "linear"); }); http://jsfiddle.net/jsfiddlr/48uEK/
  • 12. jQuery Animation: .stop() // here is solution demonstrating .stop() // and certain easing (currently "swing") $("#open-b").click(function () { $("#b").stop(true, true).animate({ height: "80px" }, duration, easing); }); $("#close-b").click(function () { $("#b").stop(true, false).animate({ height: "0" }, duration, easing); }); http://jsfiddle.net/jsfiddlr/48uEK/
  • 13. jQuery Animation: .stop() // another solution (maybe more appropriate), // but example wasn't about this $("#open-a, #close-a").click(function () { var div = $("#a"); if (div.is(":animated")) { return; } div[div.is(":visible") ? "fadeOut" :"fadeIn"](duration); }); http://jsfiddle.net/jsfiddlr/48uEK/
  • 14. jQuery Animation: .queue() // intention: smoothly show element // and then remove it from the DOM $("#b1").click(function () { // element gets removed before // animation finishes $("#a") .fadeIn(duration) .remove(); }); http://jsfiddle.net/jsfiddlr/EXNj9/
  • 15. jQuery Animation: .queue() // solution: use animation queue $("#b2").click(function () { $("#b") .fadeIn(duration) .queue(function(next) { $(this).remove(); // common pattern is to enable execution of // other animations (added after .queue() call) // by calling the next one // (in our example we could omit this) next(); }); http://jsfiddle.net/jsfiddlr/EXNj9/
  • 16. jQuery Ajax: .ajaxStart() $(this) // show spinner at ajax start .ajaxStart(function() { $(this).html( $("#spinner").clone().show()); }) // load content via ajax // when loaded it will replace spinner .load("/echo/html/", { html: "<h1>I've just loaded!</h1>", delay: 3 }); http://jsfiddle.net/jsfiddlr/t38Rx/
  • 17. jQuery Ajax: .ajaxPrefilter() // if URL contains "some" then fake request will be executed $.ajaxPrefilter(function(options, originalOptions, jqXHR) { if (options.url.indexOf("some") >= 0) { options.dataTypes = ["fake"]; } }); http://jsfiddle.net/jsfiddlr/VB9ur/
  • 18. jQuery Ajax: .ajaxTransport() // setting transport for "fake" request $.ajaxTransport("fake", function(options, originalOptions, jqXHR) { // if previous request with certain URL is finished // then process this one if (urls.indexOf(options.url) === -1) { urls += options.url; return { send: function(headers, completeCallback) { setTimeout(function() { urls = urls.replace(options.url, ""); completeCallback(200, "success", { "fake": "Success!" }); }, 5000); }, abort: function () { } }; http://jsfiddle.net/jsfiddlr/VB9ur/
  • 19. jQuery Ajax: .ajaxTransport() // otherwise alert error and send "server error" code } else { alert("Can't call same URL while waiting for response!" ); return { send: function (headers, completeCallback) { completeCallback(500, "error"); }, abort: function () { } }; } http://jsfiddle.net/jsfiddlr/VB9ur/
  • 20. Thanks! Thanks for attention and patience!  constantin.titarenko@binary-studio.com constantin.titarenko@gmail.com October 4, 2011 http://about.me/constantin.titarenko