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 7876959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:15:07+00:00 2026-06-03T03:15:07+00:00

I am experiencing an issue in jQuery when I do multiple jsonp requests, all

  • 0

I am experiencing an issue in jQuery when I do multiple jsonp requests, all with the same jsonpCallback function. It seems that only for the one of those the callback function is triggered. Are JSONP requests somehow overwriting each other?

Below an example of doing 2 jsonp request to github, and even though both firebug shows that both of them return, the callback function getName is only called for one of them:

function getName(response){
    alert(response.data.name);
}

function userinfo(username){
    $.ajax({
        url: "https://api.github.com/users/" + username,
        jsonpCallback: 'getName',
        dataType: "jsonp"
    });        
}

users = ["torvalds", "twitter", "jquery"]
for(var i = 0; i < users.length; i++){
  userinfo(users[i]);
}
  • 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-06-03T03:15:08+00:00Added an answer on June 3, 2026 at 3:15 am

    Your request fired only once because of how jsonp works.

    Jsonp means adding a script tag to the page from an outside domain to get around Cross-Site Scripting protections built into modern browsers (and now IE6 and 7 as of April 2011). In order to have that script interact with the rest of the script on the page, the script being loaded in needs to call a function on the page. That function has to exist in the global namespace, meaning there can only be one function by that name. In other words, without JQuery a single jsonp request would look like this:

    <script>
    function loadJson(json) {
        // Read the json
    }
    </script>
    <script src="//outsidedomain.com/something.js"></script>
    

    Where something.js would look like this:

    loadJson({name:'Joe'})
    

    something.js in this case has a hard-coded callback to load the JSON it carries, and the page has a hard-coded loadJson function waiting for scripts like this one to load and call it.

    Now suppose you want to be able to load json from multiple sources and tell when each finishes, or even load JSON from the same source multiple times, and be able to tell when each call finishes – even if one call is delayed so long it completes after a later call. This hard-coded approach isn’t going to work anymore, for 2 reasons:

    1. Every load of something.js calls the same loadJson() callback – you have no way of knowing which request goes with which reply.

    2. Caching – once you load something.js once, the browser isn’t going to ask the server for it again – it’s going to just bring it back in from the cache, ruining your plan.

    You can resolve both of these by telling the server to wrap the JSON differently each time, and the simple way is to pass that information in a querystring parameter like ?callback=loadJson12345. It’s as though your page looked like this:

    <script>
    function loadJson1(json) {
        // Read the json
    }
    function loadJson2(json) {
        // Read the json
    }
    </script>
    <script src="//outsidedomain.com/something.js?callback=loadJson1"></script>
    <script src="//outsidedomain.com/somethingelse.js?callback=loadJson2"></script>
    

    With JQuery, this is all abstracted for you to look like a normal call to $.ajax, meaning you’re expecting the success function to fire. In order to ensure the right success function fires for each jsonp load, JQuery creates a long random callback function name in the global namespace like JQuery1233432432432432, passes that as the callback parameter in the querystring, then waits for the script to load. If everything works properly the script that loads calls the callback function JQuery requested, which in turn fires the success handler from the $.ajax call.

    Note that "works properly" requires that the server-side reads the ?callback querystring parameter and includes that in the response, like ?callback=joe -> joe({.... If it’s a static file or the server doesn’t play this way, you likely need to treat the file as cacheable – see below.

    Caching

    If you wanted your json to cache, you can get JQuery to do something closer to my first example by setting cache: true and setting the jsonpCallback property to a string that is hardcoded into the cacheable json file. For example this static json:

    loadJoe({name:'Joe'})
    

    Could be loaded and cached in JQuery like so:

    $.ajax({
        url: '//outsidedomain.com/loadjoe.js',
        dataType: 'jsonp',
        cache: true,
        jsonpCallback: 'loadJoe',
        success: function(json) { ... }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing a weird scrollbar issue. I'm building a page that uses jQuery and
I'm currently experiencing an issue with the custom mbean SNMP publishing function that WebLogic
I'm experiencing an issue with ActiveMQ and would like to trace/view all ActiveMQ activity.
I have an XP client that is experiencing an issue. My dev box is
I am experiencing a weird issue with PUT and POST ajax CORS requests in
We are experiencing an issue where a FullTextSqlQuery is only returning the default 100
I am experiencing and issue only in IE. In FF, Safari, and Chrome, behavior
I have some HTML that gets rendered and I'm experiencing an issue with Chrome
Experiencing an issue with an Ubercart 2 store that is now running on nginx.
We are experiencing an issue where one of our deployment projects gets modified during

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.