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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:02:35+00:00 2026-05-29T04:02:35+00:00

I want to return a json object from the onreadystatechange = function(){}, but I

  • 0

I want to return a json object from the onreadystatechange = function(){}, but I failed.
Could you provide me a method to do this?
for example, when I call the function getIntervention(startdate,enddate).Then where will the json data in the “onreadystatechange = function(){}” return?

[code=JScript][/code]
function getIntervention(startdate,enddate)
{
var xmlhttp = false;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  if (XMLHttpRequest.overrideMimeType)
  {
  XMLHttpRequest.overrideMimeType("text/xml");
  }
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if(!xmlhttp)
 {
window.alert("can't create!");
return false;
}   
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  var jsondata=eval('('+xmlhttp.responseText+')');
  document.getElementById("myDiv").innerHTML=jsondata.nbMissions;
  ***return jsondata;***
  }
  else
document.getElementById("myDiv").innerHTML=xmlhttp.status+"-"+xmlhttp.readyState;
  }
xmlhttp.open("POST","proxy.jsp",true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send("url=http://aqueduc.kelcode.com/proc/gw.php&requestName=getIntervention&uid=UID_GATEWAY&startDate="+startdate+"&endDate="+enddate+"");
}
  • 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-29T04:02:35+00:00Added an answer on May 29, 2026 at 4:02 am

    You simply can’t return results from asynchronous methods.

    The only thing you can do is to queue up another function (a “callback”) that will be invoked with the result when it arrives.

    FWIW, if you were to use jQuery your entire code would just be:

    function getIntervention(startdate, enddate) {
         return $.ajax({
             url: 'proxy.jsp', 
             data: {
                 url: 'http://aqueduc.kelcode.com/proc/gw.php',
                 requestName: 'getIntervention',
                 uid: UID_GATEWAY,
                 startDate: startdate,
                 endDate: enddate
            });
    };
    
    getIntervention(a, b).done(function(jsondata) {
        // jsondata will be your data, already parsed
    });
    

    The only bit I’ve omitted is the settnig of the myDiv element.

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

Sidebar

Related Questions

I want to return a private field from a remoted object but i get
I just simply want to return a JSON object (using ajax) from my server
I want to return a set of values from function till the point they
edited: This is what i need: sendpost = function(a,b,c){ return jQuery.post('inc/operations.php', {a:b}, c, json);
I have this action method: [HttpPost] public ActionResult GetNextImage(int m_id) { ... return Json(new{...});
code //array store the markers var googleMarker = []; //this function get json object
I have a function to sort a JSON object that looks like this: function
I want to get data from thisarray of json object : [ { outgoing_relationships:
I want to split the json part from this URL in my iPhone application.
I am receiving some JSON object from the server, and I want to 'typecast'

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.