Bug Tracker

Ticket #2806 (closed feature: fixed)

Opened 1 year ago

Last modified 1 year ago

$.ajax: support for dynamic data arguments

Reported by: joern Assigned to: joern
Type: feature Priority: major
Milestone: 1.2.4 Component: ajax
Version: 1.2.3 Keywords: ajax dynamic data
Cc: Needs: Test Case

Description

A lot of plugins leverage $.ajax internally. The need to pass through additional parameters from the user comes up very often (eg. autocomplete, treeview, validation). Those parameters must be calculated at request time, eg. a value from an input field.

So far plugins have to evaluate functions before passing them trough to $.ajax. If $.ajax would do that, every ajaxified plugin could leverage that without all the hazzle.

Attachments

dynamic-test.diff (488 bytes) - added by joern 1 year ago.
test
dynamic-patch.diff (0.5 kB) - added by joern 1 year ago.
patch

Change History

Changed 1 year ago by flesler

Could you show a little example ?

Changed 1 year ago by joern

Usage in the autocomplete plugin:

function state() {
  return $("#state").val();
}
$(...).autocomplete("county.php", {
  extraParams: {
    "state": state
  }
});

Part of the implemenetation:

var extraParams = {
	timestamp: +new Date()
};
$.each(options.extraParams, function(key, param) {
	extraParams[key] = typeof param == "function" ? param() : param;
});

Changed 1 year ago by joern

Implemenetation, if the feature would be added to core, would just pass through extraParams to $.ajax instead of "parsing" it itself.

Changed 1 year ago by joern

While this isn't of much use for direct usage with $.ajax, it makes sense for $.ajaxSetup, which you call at some point before starting a request.

Changed 1 year ago by scott.gonzal

Having the same parsing for the actual data parameter would be useful too.

Changed 1 year ago by joern

test

Changed 1 year ago by joern

patch

Changed 1 year ago by joern

  • status changed from new to closed
  • resolution set to fixed

Fixed in [5478].

Note: See TracTickets for help on using tickets.