#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)
Change History (8)
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
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 15 years ago by
Implemenetation, if the feature would be added to core, would just pass through extraParams to $.ajax instead of "parsing" it itself.
comment:4 Changed 15 years ago by
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 15 years ago by
Having the same parsing for the actual data parameter would be useful too.
Could you show a little example ?