Skip to content Skip to sidebar Skip to footer

How To Add A Parameter To Url In All Ajax Calls?

I have a Backbone application using jQuery and want to append a sessionId parameter to the URL of all ajax calls? How can I do this in Backbone or jQuery, maybe in a global way an

Solution 1:

You can use the advanced options of jQuery.ajax. In your case, you should register a global prefilter to modify the sent data. Watch out to do this only on request to your own domain, otherwise that could be a security leakage.

Another option would be to create a simple wrapper function that extends the options passed in:

functionmyAjax(options) {
     options.url = "mydomain";
     options.data = $.extend(options.data||{}, {sessionID: 12345});
     return $.ajax(options);
 }

Solution 2:

You can use the global .ajaxSend() event.

Post a Comment for "How To Add A Parameter To Url In All Ajax Calls?"