You can use the $ .ajaxSetup ({}) method in jQuery to configure some general ajax settings.
For example, if you are going to post on the same URL over and over on any page, you can simply set this to ajaxSetup. This would mean that you would have to pass less parameters to the function, for example, as Richard did. Any property of the first parameter of the ajax method can be set as the default value in $ .ajaxSetup ().
$.ajaxSetup({ url: 'my/ajax/url' success: function() {
They can be overridden by any ajax call. So now you can just do:
$.ajax({data:{foo:'bar',bar:'foo'}});
And you can redefine the url like:
$.ajax({url:'different/ajax/url',data:{foo:'bar',bar:'foo'}});
source share