Thank you very much! Great idea!
Here is my implementation, works so far:
(function ($) {
var _ajax = $.ajax,
A = $.ajax = function(options) {
if (A.data)
if(options.data) {
if(typeof options.data !== 'string')
options.data = $.param(options.data);
if(typeof A.data !== 'string')
A.data = $.param(A.data);
options.data += '&' + A.data;
} else
options.data = A.data;
return _ajax(options);
};
})(jQuery);
On Sep 22, 10:57 pm, Nathan Bubna <[email protected]> wrote:
> My JSON-REST plugin does this by wrapping $.ajax with other method(s).
> Just add an object of params to
> $.rest.data.http://plugins.jquery.com/project/rest
>
> You can do this by wrapping/replacing the $.ajax method yourself
>
> (function ($) {
>
> var _ajax = $.ajax,
> A = $.ajax = function(options) {
> if (A.data) {
> //TODO: the appending in here, i just don't feel like
> writing all of this
> }
> return _ajax(options);
> };
> };
>
> })(jQuery);
>
> // then make a call this:
> $.ajax.data = { myParam: 'alwaysAppendThis' };
> // and all your ajax calls will get that data
> $.get({...})
> $.post({...})
> // and so on
>
> On Tue, Sep 22, 2009 at 1:18 AM, gMinuses <[email protected]> wrote:
>
> > Is there a way to automatically append some parameters in every ajax
> > call's query string?
>
> > "ajaxStart" event doesn't send ajax options to callback function, so
> > there is not way to modify the query string.
>
> > "ajaxSend" event doesn't work with GET request, because the query
> > string is already appended to the url and xhr is already open, so
> > there is no way to change the url.
>
> > For "beforeSend", it's the same as "ajaxSend".
>
> > Set global setting in ajaxSetup will not work, if "data" is specified
> > in individual ajax calls.
>
> > I'd like to add parameters like 'mode=ajax' to make server respond as
> > little data as posible(e.g, no header, no footer), and degrade
> > gracefully.
>
> > I have many ajax calls to make, and adding these parameters to every
> > single of them manually is very tedious.
>
> > So how can I achieve this in jQuery?
>
> > Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---