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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:07+00:00 2026-05-26T11:42:07+00:00

I am trying to get a JSONP response from Twitter and have the following

  • 0

I am trying to get a JSONP response from Twitter and have the following code:

<!doctype html>
<html>
    <head>
    </head>
    <body>
        <script>
            (function($, container) {

                container[$] = function(url){

                    url += '&callback=jsonp';

                    var scriptEl = document.createElement('script');

                    scriptEl.setAttribute('src', url);

                    document.getElementsByTagName('head')[0].appendChild(scriptEl);

                }

                window.jsonp = function(response) {

                    return response;

                }

            })('$', this);
        </script>
        <script>
            var test = $('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jonathonoates');

        </script>
    </body>
</html>

If instead of return response; in the window.jsonp function, I were to stick an alert(response) I can see that I am getting a successful response from Twitter.

I would like to return that response, as in the var test = $('http...');, but test is undefined; the response is not being returned.

I am sure I’m looking at it silly, it’s probably something to do with it being inside the closure?

I’d really appreciate you help with this!

Though, please, no jQuery etc. answers, as I’d like to learn how all this done by myself.

Thank you everyone!

  • 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-26T11:42:07+00:00Added an answer on May 26, 2026 at 11:42 am

    Due to the behaviour of asynchronous calls, the callback function must be called after the JSONP has been retrieved from the source, in this case, Twitter.

    The callback function should be passed as an argument along with the URL in the $ function so it can be called from within the jsonp function, that should be a child of the $ function.

                    url += '&callback=jsonp';
    
                    var scriptEl = document.createElement('script');
    
                    scriptEl.setAttribute('src', url);
    
                    head.appendChild(scriptEl);
    
                    container.jsonp = function(response) {
    
                        return callback(response);
    
                    }
    

    and called like:

            function test(x) {
                alert(x);
            }
    
            $(test, 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jonathonoates');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get a response from a function in a webservice but i
I'm trying to get a jsonp callback working using jquery within a greasemonkey script.
I am trying to get the list of specific user`s friends from twitter. This
i am trying to get only JSON response from a webservice. i am getting
I'm having a hardcore head-ache from trying to get complete programmatic control over rendering
I've been trying to get a json response from google's geocoding service. I'm using
I am trying to get a JSON response from our server and the response
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,
I'm trying to get a json string back from my controller, that is prefill-values
I'm trying to get the JSON object from a JSON outputted string from 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.