Ticket #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: | |
| 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
Change History
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Could you show a little example ?