Bug Tracker

Modify

Ticket #2806 (closed feature: fixed)

Opened 5 years ago

Last modified 14 months ago

$.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:
Blocking: Blocked by:

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 Download (488 bytes) - added by joern 5 years ago.
test
dynamic-patch.diff Download (540 bytes) - added by joern 5 years ago.
patch

Change History

comment:1 Changed 5 years ago by flesler

Could you show a little example ?

comment:2 Changed 5 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 5 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 5 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 5 years ago by scott.gonzal

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

Changed 5 years ago by joern

test

Changed 5 years ago by joern

patch

comment:6 Changed 5 years ago by joern

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

Fixed in [5478].

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.