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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:28:42+00:00 2026-05-16T00:28:42+00:00

So I was reading through the code on Malsup’s twitter plugin and I noticed

  • 0

So I was reading through the code on Malsup’s twitter plugin and I noticed he’d written his own method to handle jsonp but with timeouts and errors. I can only assume the built in jQuery method ‘getJSON’ doesn’t have this functionality even though it clearly works fine.

So, should I continue to use Malsups version in my projects where I’m making JSONP requests or just stick with jQuery’s method. I have emailed Malsup and Paul Irish to ask about why it was necessary to write this but I didn’t hear back. Can’t blame ’em really:)

$.getJSONP = function(s){
    s.dataType = 'jsonp';
    $.ajax(s);

    // figure out what the callback fn is
    var $script = $(document.getElementsByTagName('head')[0].firstChild);
    var url = $script.attr('src') || '';
    var cb = (url.match(/callback=(\w+)/) || [])[1];
    if (!cb) 
        return; // bail
    var t = 0, cbFn = window[cb];

    $script[0].onerror = function(e){
        $script.remove();
        handleError(s, {}, "error", e);
        clearTimeout(t);
    };

    if (!s.timeout) 
        return;

    window[cb] = function(json){
        clearTimeout(t);
        cbFn(json);
        cbFn = null;
    };

    t = setTimeout(function(){
        $script.remove();
        handleError(s, {}, "timeout");
        if (cbFn) 
            window[cb] = function(){
            };
    }, s.timeout);

    function handleError(s, o, msg, e){
        // support jquery versions before and after 1.4.3
        ($.ajax.handleError || $.handleError)(s, o, msg, e);
    }
};
  • 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-16T00:28:42+00:00Added an answer on May 16, 2026 at 12:28 am

    From the jQuery docs for getJSON(…)

    Important: As of jQuery 1.4, if the
    JSON file contains a syntax error, the
    request will usually fail silently
    .
    Avoid frequent hand-editing of JSON
    data for this reason. JSON is a
    data-interchange format with syntax
    rules that are stricter than those of
    JavaScript’s object literal notation.
    For example, all strings represented
    in JSON, whether they are properties
    or values, must be enclosed in
    double-quotes. For details on the JSON
    format, see http://json.org/.

    Presumably, silent failure was not something they liked, hence the plugin. In your case, if you’re making JSONP requests and find yourself using the onError, or onTimeout methods, then keep the plugin. I’ve not had to use JSONP in any real capacity, but I would assume that error handling is always nice to have. In the link to the jQuery docs, there is good discussion on this towards the end of the comments

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

Sidebar

Related Questions

I noticed while reading through my code that I have a static member function
I'm reading through some old code at work, and have noticed that there are
I'm reading through the LZMA SDK source code and noticed that they assign pointers
I've been reading through a few asp.net articles, and attempting some code, but I
I'm trying to code my own DNS server, I'm reading through RFC1035 on DNS
Reading through the SendAsync , BeginAsync method illustrations of Socket s, I realized that
I'm currently reading through this jquery masking plugin to try and understand how it
I was reading through some code (C, if it makes a difference to anyone)
I was reading through our code base at my company and I saw something
I was reading through some source code recently that updated the code on a

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.