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

The Archive Base Latest Questions

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

I wish to request data from a web service endpoint( say http://www.example.com ) using

  • 0

I wish to request data from a web service endpoint( say “http://www.example.com“) using javascript.

After retrieving it , there will be a callback function to process the response ( which will be a JSON object )

How do I go about writing it? A skeleton code will do.

Will it be something like:

<script>

function callback(data)
{
    // the response text would be processed here.
}
       url="http://www.example.com";
       var script = document.createElement('script');
       script.src = url;
       script.onload=callback;
       document.body.appendChild(script);        
</script>

Thanks in advance.

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

    As noted by @JuicyScripter in the comment above…

    “Wikimedia API which Wikipedia use supports JSONP callback argument.”

    This means that you can add a callback to the query…

    var url = "http://en.wikipedia.org/w/api.php?action=query&prop=info|revisions&intoken=edit&titles=Main%20Page&format=json&callback=my_callback";
    

    Notice at the end I added &callback=my_callback. What will happen is that instead of sending a JSON response like…

    {
        query: {
            pages: {
                15580374: {
                    ...
                }
            }
        }
    }
    

    …it will now be wrapped in a function call. This will be valid JavaScript, so your script request will execute the function, and pass the data.

    my_callback({
        query: {
            pages: {
                15580374: {
                    ...
                }
            }
        }
    });
    

    So all you need is a callback function that has the same name as the function you gave in the query…

    function my_callback( data ) {
        console.log( data );
    }
    

    Make sure this function is globally available.

    Then get rid of the onload line, and your code should just work…

    var url = "http://en.wikipedia.org/w/api.php?action=query&prop=info|revisions&intoken=edit&titles=Main%20Page&format=json&callback=my_callback";
    var script = document.createElement('script');
    script.src = url;
    document.body.appendChild(script);     
    

    When the script arrives and runs, it will invoke your function passing it the data requested.

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

Sidebar

Related Questions

I wish to migrate the database of a legacy web app from SQL Server
I am trying to do what ever is explained in here http://middlewaremagic.com/weblogic/?p=2019 My web.xml
After a user enters data on my home page, I wish to send the
i wish to send some data as array from my iphone app to server
I wish to know all the pros and cons about using these two methods.
I wish to perform an experiment many different times. After every trial, I am
I have a WCF service that uses Message contract for request and replies of
I have a function using AFJSONRequestOperation, and I wish to return the result only
i am trying to return just one piece of data from amazon by connecting
My web server has a lot of dependencies for sending back data, when it

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.