+test(".ajax() - hash", function() {
+ expect(3);
+
+ jQuery.ajax({
+ url: "data/name.html#foo",
+ beforeSend: function( xhr, settings ) {
+ equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ url: "data/name.html?abc#foo",
+ beforeSend: function( xhr, settings ) {
+ equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ url: "data/name.html?abc#foo",
+ data: { "test": 123 },
+ beforeSend: function( xhr, settings ) {
+ equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
+ return false;
+ }
+ });
+});
+
+test(".ajax() - 304", function() {
+ expect( 1 );
+ stop();
+
+ jQuery.ajax({
+ url: url("data/notmodified.php"),
+ success: function(){ ok(true, "304 ok"); },
+ error: function(){ ok(false, "304 not ok "); },
+ complete: function(xhr){ start(); }
+ });
+});
+
+test(".load()) - 404 error callbacks", function() {
+ expect( 6 );
+ 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("<div/>").load("data/404.html", function(){
+ ok(true, "complete");
+ });
+});
+
+test("jQuery.ajax() - abort", function() {
+ expect( 6 );
+ stop();
+
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ });
+
+ var xhr = jQuery.ajax({
+ url: url("data/name.php?wait=5"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+
+ xhr.abort();
+});
+
+test("Ajax events with context", function() {
+ expect(14);
+
+ stop();
+ var context = document.createElement("div");
+
+ function event(e){
+ equals( this, context, e.type );
+ }
+
+ function callback(msg){
+ return function(){
+ equals( this, context, "context is preserved on callback " + msg );
+ };
+ }
+
+ function nocallback(msg){
+ return function(){
+ equals( typeof this.url, "string", "context is settings on callback " + msg );
+ };
+ }
+
+ jQuery('#foo').add(context)
+ .ajaxSend(event)
+ .ajaxComplete(event)
+ .ajaxError(event)
+ .ajaxSuccess(event);
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: callback("beforeSend"),
+ success: callback("success"),
+ error: callback("error"),
+ complete:function(){
+ callback("complete").call(this);
+
+ jQuery.ajax({
+ url: url("data/404.html"),
+ context: context,
+ beforeSend: callback("beforeSend"),
+ error: callback("error"),
+ complete: function(){
+ callback("complete").call(this);
+
+ jQuery('#foo').add(context).unbind();
+
+ jQuery.ajax({
+ url: url("data/404.html"),
+ beforeSend: nocallback("beforeSend"),
+ error: nocallback("error"),
+ complete: function(){
+ nocallback("complete").call(this);
+ start();
+ }
+ });
+ }
+ });
+ },
+ context:context
+ });
+});
+
+test("jQuery.ajax context modification", function() {
+ expect(1);
+
+ stop();
+
+ var obj = {}
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ context: obj,
+ beforeSend: function(){
+ this.test = "foo";
+ },
+ complete: function() {
+ start();
+ }
+ });
+
+ equals( obj.test, "foo", "Make sure the original object is maintained." );
+});
+