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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:28:27+00:00 2026-05-31T02:28:27+00:00

I’m trying to use jQuery-jsonp plugin with jQuery Deferred Objects but I’m having no

  • 0

I’m trying to use jQuery-jsonp plugin with jQuery Deferred Objects but I’m having no luck so far.

The goal is to call an API, retrieve data and elaborate them. Since I’m using the same call to retrieve and elaborate different sets of data for different purposes, I structured my code this way to avoid explicitly repeating the same API call in each elaborating function:

function callAPI(){
  return $getJSON(url);
}

function doStuff1(){
  $.when(callAPI)
  .then(function(data){
    //get the data and elaborate them for purpose #1
  })
}

function doStuff2(){
  $.when(callAPI)
  .then(function(data){
    //get a different set of data from same API
    // and elaborate them for purpose #2
  })
}

Problem is, I tried the same approach substituting $.getJSON() with $.jsonp() from Julian Aubourg’s plugin (http://code.google.com/p/jquery-jsonp/) but the deferring doesn’t work.

I have a few restrictions on this and can’t change them:

*API calls must use JSONP.

*I must be able to detect errors (no matter what kind), hence the use of jQuery-jsonp plugin, the only solution I found so far.

I studied jQuery Deferred Object, searched jQuery forums, Stackoverflow and the depths of the web, and read everything on the plugin page. I tried several approaches, but none has worked so far (it’s as if the deferred wasn’t even there).
My hypothesis is that the deferreds don’t work with jquery-jsonp plugin because of its structure (which is what allows it to catch errors), and because $.jsonp is not a deferred itself like $.ajax is, but I’m in no way an expert so I need some advice from this splendid community.

One solution I found, and it works for me, is to pass a function as a parameter to the callAPI function, so on success it can execute what I need without repeating myself.

So my callAPI function would be changed like this:

function callAPI(func){
 $.jsonp({
   "url": url,
   "success": function(data) {
     func();
   },
   "error": function(d,msg) {
    //show error message
   }
 })
}

callAPI(doStuff1);
//or
callAPI(doStuff2);

But, since the error management necessity came out late in the development stage and I, being a newbie, didn’t think about it earlier, this would mean rewriting a whole bunch of code. So if someone managed to use deferreds with jquery-jsonp plugin, that would be great to know.

Thank you all.

Flavia

  • 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-31T02:28:28+00:00Added an answer on May 31, 2026 at 2:28 am

    I think this is what you want. You have to map jQuery-jsonp’s internal api to calling methods on the deferred object.

    function callAPI(url){
      return $.Deferred(function(dfd) {
        $.jsonp({
          url: url
          ,success: dfd.resolve
          ,error: dfd.reject
          ,complete: dfd.always
        });
      }).promise();
    }
    

    Then you should be able to use

    $.when(callAPI('url #1'), callAPI('url #2'))
      .done(function(response1, response2) {
        // each response will be [ json , STR_SUCCESS ] based on Jquery-jsonp's API
        var json1 = response1[0];
        ...
      })
      .error(function(error1, error2) {
        // each response will be [ xOptions , type ] based on Jquery-jsonp's API
        ...
      })
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.