Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#2806 closed feature (fixed)

$.ajax: support for dynamic data arguments

Reported by: joern Owned by: joern
Priority: major Milestone: 1.2.4
Component: ajax Version: 1.2.3
Keywords: ajax dynamic data Cc:
Blocked by: Blocking:

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 (2)

dynamic-test.diff (488 bytes) - added by joern 12 years ago.
test
dynamic-patch.diff (540 bytes) - added by joern 12 years ago.
patch

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by flesler

Could you show a little example ?

comment:2 Changed 12 years 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;
});

comment:3 Changed 12 years ago by joern

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

comment:4 Changed 12 years 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.

comment:5 Changed 12 years ago by scott.gonzal

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

Changed 12 years ago by joern

Attachment: dynamic-test.diff added

test

Changed 12 years ago by joern

Attachment: dynamic-patch.diff added

patch

comment:6 Changed 12 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in [5478].

Note: See TracTickets for help on using tickets.