Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:20:55+00:00 2026-05-31T14:20:55+00:00

I use this jQuery Ajax-Request, which I configured for my needs: jQuery.ajax({ url: apiBridge.php?url=

  • 0

I use this jQuery Ajax-Request, which I configured for my needs:

jQuery.ajax({
    url: "apiBridge.php?url=" +  encodeURIComponent(url),
    headers: {
        "Some Weird Header": "123"
    },
    success: function(data){

    },
    complete: function(){
        doAlotOfStuff();
        andMore();
    }
});

The real code is fairly lengthy and I consider it stupid to copy/paste the whole thing every time I need to make an Ajax-request in my style.

What I want to do, is to define this function once, so I am able to re-use it. All I need to change for each instace of the function is the url and success callback.

What is the right way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:20:57+00:00Added an answer on May 31, 2026 at 2:20 pm

    Define a set of standard options:

    var ajaxOpts = {
        headers:{},
        url:"someUrl",
        complete:function(){//whatever;},
        otheroptions:"asneeded"
    };
    

    When you make each ajax call, extend the local options object with the standard options:

    $.ajax($.extend({url:"custom", success:doAThing}, ajaxOpts));
    

    …or as @gdoron says, use ajaxSetup. I prefer $.extend because that way I’m not clobbering other $.ajax calls on the page I might not control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My jQuery code (using ajax) request's data from a local php script (pgiproxy.php). This
I have an AJAX request on a php file, which returns some data, like
I need help to use jConfirm with this existing code (php & Jquery &
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
Does jQuery.ajax({async: false}) still use the XMLHttpRequest object? If so, how is the request
I use jQuery AJAX with cache: false . This adds a '_': '[Timestamp]' in
I'm trying to use the DataTables jQuery plug-in in MVC3 using an ajax request
I am trying to use this jQuery plugin (jsTree) in one of my project.
I generally use this in jquery $(document).ready(function() { //stuff } I was just on
Im trying to use this page slider jquery plugin, you can see the demo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.