Bug Tracker

Modify

Ticket #8277 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

Default data, setuped via ajaxSetup do not send in get and load functions, if use callback function.

Reported by: whitefur@… Owned by: jaubourg
Priority: high Milestone: 1.5.1
Component: ajax Version: 1.5
Keywords: Cc: jaubourg
Blocking: Blocked by:

Description

If set default data via ajaxSetup() For example

$.ajaxSetup({
 data : {'kid' : 'mike'}
})

And then use load('url',callback) , whith callback, data do not send to the server.

If use load('url') - All works correctly. Same bug in get function....

In both functions, if second argument is a callback function, jQuery set data param to NULL value, and then it value rewrite default ajaxSettings.data in extend() function. Correctly use UNDEFINED value, because in extend() fucntion use hard type hinting ...

} else if ( copy !== undefined ) {
 target[ name ] = copy;
}

.... Actually both for version 1.5, and for version 1.4

Change History

comment:1 Changed 3 years ago by jitter

  • Cc jaubourg added
  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to ajax
  • Milestone changed from 1.next to 1.5.1

Thanks for taking the time to contribute to the jQuery project by writing a bug report.

 test case

It seems like most of the ajax shorthand functions are affected by this since 1.4 . As the reporter pointed out this happens because the utility functions set data to null when the second parameter is a function.

Affected functions: .get/.post/.load (.getJSON / .getScript too because they use .get internally)

Offending lines are  https://github.com/jquery/jquery/blob/1.5/src/ajax.js#L232 and  https://github.com/jquery/jquery/blob/1.5/src/ajax.js#L140

comment:2 Changed 3 years ago by jaubourg

  • Owner set to jaubourg
  • Status changed from open to assigned

comment:3 Changed 3 years ago by jaubourg

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixes #8277. Sets data to undefined rather than null when it is not provided in ajax helpers so that it won't revent data set in ajaxSettings from being used. Unit test added.

Changeset: 1ddfdabbb983e2d3bf7f7200a3da5051f274e6fe

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.