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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:05:35+00:00 2026-06-04T21:05:35+00:00

I have a web application that receives json from a server. I was using

  • 0

I have a web application that receives json from a server. I was using this code:

var http_request = new XMLHttpRequest();
var url = "url where I have the json"
http_request.onreadystatechange = handle_json;
http_request.open("GET", url, true);
http_request.send(null);
var obj;

function handle_json() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
     var json_data = http_request.responseText; 
     obj = eval("(" + json_data + ")");
     processData(obj);

} else {
  alert("A problem ocurred");
}
http_request = null;

}
}

But now I want to receive json from two url’s and show the information. How can I do this using JavaScript? I know eval is not the appropiate thing to do but this is just a prototype.

Thank you so much! 🙂

  • 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-04T21:05:36+00:00Added an answer on June 4, 2026 at 9:05 pm

    As others have mentioned, you simply need to make 2 requests. In order to re-use the code you have already written, you could define a function to get json that takes a url argument. Something like this:

    function getJson(url, callback){
      function handle_json() {
        if (http_request.readyState == 4) {
          if (http_request.status == 200) {
            var json_data = http_request.responseText;
            var parser = (JSON && typeof JSON.parse == 'function') ? JSON.parse : eval;
            var obj = parser("(" + json_data + ")");
            callback(obj);
          } else {
            alert("A problem ocurred");
          }
          http_request = null;
        }
      }
    
      var http_request = new XMLHttpRequest();
      http_request.onreadystatechange = handle_json;
      http_request.open("GET", url, true);
      http_request.send(null);
    }
    

    I replaced the call to eval with some logic that will call JSON.parse if it is present, otherwise it will use eval. Using this function would allow you to make multiple requests by calling it multiple times, like so:

    getJson("some url", processData);
    getJson("some other url", processData");
    

    If you wanted to process data from different urls in different ways, just define another function similar to processData and pass it along instead, like getJson("some crazy url", processCrazyData);

    Using a framework like jQuery would reduce the amount of code that you have to write, but this solution should get it done using basic javascript.

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

Sidebar

Related Questions

I have an server application (running as a Windows Service) that receives calls from
Currently I have an application that receives an uploaded file from my web application.
I have a web application that runs multiple websites from one codebase. I have
I have a web application that is deployed to a server. I am trying
I have some web application that uses jQuery to send AJAX requests to server.
Ti.SDK 1.6.2 iOS 4.3 I have a web application that receives post data as
I currently have a TCP server application written in .Net that receives and submits
I have a web application that is polling a web service on another server.
I have a server application that receives information over a network and processes it.
I have a J2EE application that receives messages (events) via a web service. The

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.