Skip to content

Commit af67883

Browse files
committed
Tabs: Set ajaxOptions in intial $.ajax() call. Fixes #8504 - Ajax in Tabs not passing data in 1.9. beta 1.
1 parent 536d112 commit af67883

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

tests/unit/tabs/tabs_deprecated.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ test( "panel ids", function() {
2525
module( "tabs (deprecated): options" );
2626

2727
asyncTest( "ajaxOptions", function() {
28-
expect( 1 );
28+
expect( 2 );
2929

3030
var element = $( "#tabs2" ).tabs({
3131
ajaxOptions: {
32+
data: "foo=bar",
3233
converters: {
3334
"text html": function() {
3435
return "test";
3536
}
3637
}
3738
}
3839
});
40+
element.one( "tabsbeforeload", function( event, ui ) {
41+
equal( ui.ajaxSettings.url.replace( /^[^\?]+/, "" ), "?foo=bar", "ajaxOptions.data" );
42+
});
3943
element.one( "tabsload", function( event, ui ) {
4044
equal( $( ui.panel ).html(), "test" );
4145
start();

ui/jquery.ui.tabs.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,7 @@ $.widget( "ui.tabs", {
792792
return;
793793
}
794794

795-
this.xhr = $.ajax({
796-
url: anchor.attr( "href" ),
797-
beforeSend: function( jqXHR, settings ) {
798-
return that._trigger( "beforeLoad", event,
799-
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
800-
}
801-
});
795+
this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
802796

803797
// support: jQuery <1.8
804798
// jQuery <1.8 returns false if the request is canceled in beforeSend,
@@ -835,6 +829,18 @@ $.widget( "ui.tabs", {
835829
}
836830
},
837831

832+
// TODO: Remove this function in 1.10 when ajaxOptions is removed
833+
_ajaxSettings: function( anchor, event, eventData ) {
834+
var that = this;
835+
return {
836+
url: anchor.attr( "href" ),
837+
beforeSend: function( jqXHR, settings ) {
838+
return that._trigger( "beforeLoad", event,
839+
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
840+
}
841+
};
842+
},
843+
838844
_getPanelForTab: function( tab ) {
839845
var id = $( tab ).attr( "aria-controls" );
840846
return this.element.find( this._sanitizeSelector( "#" + id ) );
@@ -860,6 +866,7 @@ if ( $.uiBackCompat !== false ) {
860866
}
861867
});
862868

869+
// TODO: Remove _ajaxSettings() method when removing this extension
863870
// ajaxOptions and cache options
864871
$.widget( "ui.tabs", $.ui.tabs, {
865872
options: {
@@ -879,19 +886,6 @@ if ( $.uiBackCompat !== false ) {
879886
return;
880887
}
881888

882-
$.extend( ui.ajaxSettings, that.options.ajaxOptions, {
883-
error: function( xhr, s, e ) {
884-
try {
885-
// Passing index avoid a race condition when this method is
886-
// called after the user has selected another tab.
887-
// Pass the anchor that initiated this request allows
888-
// loadError to manipulate the tab content panel via $(a.hash)
889-
that.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
890-
}
891-
catch ( e ) {}
892-
}
893-
});
894-
895889
ui.jqXHR.success(function() {
896890
if ( that.options.cache ) {
897891
$.data( ui.tab[ 0 ], "cache.tabs", true );
@@ -900,6 +894,23 @@ if ( $.uiBackCompat !== false ) {
900894
}});
901895
},
902896

897+
_ajaxSettings: function( anchor, event, ui ) {
898+
var ajaxOptions = this.options.ajaxOptions;
899+
return $.extend( {}, ajaxOptions, {
900+
error: function( xhr, s, e ) {
901+
try {
902+
// Passing index avoid a race condition when this method is
903+
// called after the user has selected another tab.
904+
// Pass the anchor that initiated this request allows
905+
// loadError to manipulate the tab content panel via $(a.hash)
906+
ajaxOptions.error(
907+
xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
908+
}
909+
catch ( e ) {}
910+
}
911+
}, this._superApply( arguments ) );
912+
},
913+
903914
_setOption: function( key, value ) {
904915
// reset cache if switching from cached to not cached
905916
if ( key === "cache" && value === false ) {

0 commit comments

Comments
 (0)