- expect( 8 );
- stop();
-
- jQuery('#foo').ajaxStart(function(){
- ok( true, "ajaxStart" );
- }).ajaxStop(function(){
- ok( true, "ajaxStop" );
- start();
- }).ajaxSend(function(){
- ok( true, "ajaxSend" );
- }).ajaxComplete(function(){
- ok( true, "ajaxComplete" );
- }).ajaxError(function(){
- ok( true, "ajaxError" );
- }).ajaxSuccess(function(){
- ok( false, "ajaxSuccess" );
- });
-
- jQuery.ajaxSetup({ timeout: 500 });
-
- jQuery.ajax({
- url: url("data/name.php?wait=5"),
- beforeSend: function(){ ok(true, "beforeSend"); },
- success: function(){ ok(false, "success"); },
- error: function(){ ok(true, "error"); },
- complete: function(){ ok(true, "complete"); }
- });
+ expect( 8 );
+ stop();
+
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( true, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( false, "ajaxSuccess" );
+ });
+
+ jQuery.ajaxSetup({ timeout: 500 });
+
+ jQuery.ajax({
+ url: url("data/name.php?wait=5"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ success: function(){ ok(false, "success"); },
+ error: function(){ ok(true, "error"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+});
+
+test("Ajax events with context", function() {
+ expect(6);
+
+ stop();
+ var context = {};
+
+ function event(e){
+ equals( this, context, e.type );
+ }
+
+ function callback(){
+ equals( this, context, "context is preserved on callback" );
+ }
+
+ jQuery('#foo').add(context)
+ .ajaxSend(event)
+ .ajaxComplete(event)
+ .ajaxError(event)
+ .ajaxSuccess(event);
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: callback,
+ success: callback,
+ error: callback,
+ complete:function(){
+ callback.call(this);
+ setTimeout(proceed, 300);
+ },
+ context:context
+ });
+
+ function proceed(){
+ jQuery('#foo').add(context).unbind();
+ start();
+ }