Skip to main content

Bug Tracker

Side navigation

#1080 closed bug (fixed)

Opened March 28, 2007 02:36AM UTC

Closed August 19, 2007 11:38PM UTC

$.get(url, callback) overwrites default 'data' parameter

Reported by: spinal007 Owned by: john
Priority: major Milestone: 1.1.4
Component: ajax Version: 1.1.3
Keywords: ajax data Cc:
Blocked by: Blocking:
Description

Please see the code and comments below for explanation...

   // Consider the following default settings
   $.ajaxSetup({
    data:{'var1':'A', 'var2':'B'}
   });
   
   $(document.body).click(function(){
    // TEST 1
    $.get('/test1/', function(r){ });
    //RESULT: GET http://localhost/test1/
    //WRONG: Missing var1=A&var2=B
    
    // TEST 2
    $.get('/test2/', null, function(r){ });
    //RESULT: GET http://localhost/test2/
    //WRONG: Missing var1=A&var2=B
    
    // TEST 3
    $.get('/test3/', {}, function(r){ });
    //RESULT: GET http://localhost/test3/?
    //WRONG: Missing var1=A&var2=B
    
    // TEST 4
    $.get('/test4/', {'var3':'C'});
    //RESULT: GET http://localhost/test4/?var3=C
    //WRONG: Missing var1=A&var2=B
    
    // TEST 5
    $.get('/test5/');
    //RESULT: GET http://localhost/test5/
    //WRONG: Missing var1=A&var2=B
   });

Attachments (0)
Change History (3)

Changed April 05, 2007 03:27PM UTC by malsup comment:1

I'm not sure I agree with test 2, 3 and 4. Are you suggesting that the default data is *always* added to the request url? That's not how the other options work. For all the other options, values that are provided on the $.get call override those provided in ajaxSettings. We could achieve the same behavior using this as the first line in $.ajax:

 
if (s && s.data == window.undefined) s.data = jQuery.ajaxSettings.data; 

and changing the line in $.get that sets data = null to

 
data = window.undefined; 

Changed July 21, 2007 01:20AM UTC by john comment:2

description: Please see the code and comments below for explanation...\ \ {{{\ // Consider the following default settings\ $.ajaxSetup({\ data:{'var1':'A', 'var2':'B'}\ });\ \ $(document.body).click(function(){\ // TEST 1\ $.get('/test1/', function(r){ });\ //RESULT: GET http://localhost/test1/\ //WRONG: Missing var1=A&var2=B\ \ // TEST 2\ $.get('/test2/', null, function(r){ });\ //RESULT: GET http://localhost/test2/\ //WRONG: Missing var1=A&var2=B\ \ // TEST 3\ $.get('/test3/', {}, function(r){ });\ //RESULT: GET http://localhost/test3/?\ //WRONG: Missing var1=A&var2=B\ \ // TEST 4\ $.get('/test4/', {'var3':'C'});\ //RESULT: GET http://localhost/test4/?var3=C\ //WRONG: Missing var1=A&var2=B\ \ // TEST 5\ $.get('/test5/');\ //RESULT: GET http://localhost/test5/\ //WRONG: Missing var1=A&var2=B\ });\ \ }}}\ Please see the code and comments below for explanation... \ \ {{{ \ // Consider the following default settings \ $.ajaxSetup({ \ data:{'var1':'A', 'var2':'B'} \ }); \ \ $(document.body).click(function(){ \ // TEST 1 \ $.get('/test1/', function(r){ }); \ //RESULT: GET http://localhost/test1/ \ //WRONG: Missing var1=A&var2=B \ \ // TEST 2 \ $.get('/test2/', null, function(r){ }); \ //RESULT: GET http://localhost/test2/ \ //WRONG: Missing var1=A&var2=B \ \ // TEST 3 \ $.get('/test3/', {}, function(r){ }); \ //RESULT: GET http://localhost/test3/? \ //WRONG: Missing var1=A&var2=B \ \ // TEST 4 \ $.get('/test4/', {'var3':'C'}); \ //RESULT: GET http://localhost/test4/?var3=C \ //WRONG: Missing var1=A&var2=B \ \ // TEST 5 \ $.get('/test5/'); \ //RESULT: GET http://localhost/test5/ \ //WRONG: Missing var1=A&var2=B \ }); \ \ }}} \
milestone: 1.21.1.4
owner: → john
priority: criticalmajor
version: 1.1.11.1.3

Changed August 19, 2007 11:38PM UTC by john comment:3

resolution: → fixed
status: newclosed

Fixed in SVN rev [2783].