How can I return that values

Discussion in 'Javascript' started by Mariano, Jan 14, 2008.

  1. Mariano

    Mariano Guest

    Then, I have this script:

    function mainFunction(src, type) {
    // ...
    if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open(type, src, true);
    XMLHttpRequestObject.onreadystatechange = function(){
    if (XMLHttpRequestObject.readyState == 4 &&
    XMLHttpRequestObject.status == 200) {
    var xmlDocument = XMLHttpRequestObject.responseXML;
    var returnValue = calling(); //<==FUNCT
    }
    }
    XMLHttpRequestObject.send(null);
    }

    }

    function calling() (see the //<==FUNCT marker), when executed, return
    a boolean value. Now since this function, is never called directly,
    but always from mainFunction() function [and through anonymouse
    function], I need that mainFunction return at the end the same value
    of calling() execution [returnValue]. How can I do It?
    Thanks.
     
    Mariano, Jan 14, 2008
    #1
    1. Advertising

  2. Mariano wrote:
    > function mainFunction(src, type) {
    > // ...
    > if(XMLHttpRequestObject) {
    > XMLHttpRequestObject.open(type, src, true);
    > XMLHttpRequestObject.onreadystatechange = function(){
    > if (XMLHttpRequestObject.readyState == 4 &&
    > XMLHttpRequestObject.status == 200) {
    > var xmlDocument = XMLHttpRequestObject.responseXML;
    > var returnValue = calling(); //<==FUNCT
    > }
    > }
    > XMLHttpRequestObject.send(null);
    > }
    >
    > }
    >
    > function calling() (see the //<==FUNCT marker), when executed, return
    > a boolean value. Now since this function, is never called directly,
    > but always from mainFunction() function [and through anonymouse
    > function], I need that mainFunction return at the end the same value
    > of calling() execution [returnValue]. How can I do It?


    You can't. Since your HTTP request is handled asynchronously (as indicated
    by the `true' value as third argument of XHR::eek:pen()), the execution context
    of mainFunction() is probably left before the event listener is called.

    What *exactly* are you trying to do?


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Jan 14, 2008
    #2
    1. Advertising

  3. Mariano

    Mariano Guest

    On 14 Gen, 22:23, Thomas 'PointedEars' Lahn <>
    wrote:
    > Mariano wrote:
    > > function mainFunction(src, type) {
    > > // ...
    > > if(XMLHttpRequestObject) {
    > > XMLHttpRequestObject.open(type, src, true);
    > > XMLHttpRequestObject.onreadystatechange = function(){
    > > if (XMLHttpRequestObject.readyState == 4 &&
    > > XMLHttpRequestObject.status == 200) {
    > > var xmlDocument = XMLHttpRequestObject.responseXML;
    > > var returnValue = calling(); //<==FUNCT
    > > }
    > > }
    > > XMLHttpRequestObject.send(null);
    > > }

    >
    > > }

    >
    > > function calling() (see the //<==FUNCT marker), when executed, return
    > > a boolean value. Now since this function, is never called directly,
    > > but always from mainFunction() function [and through anonymouse
    > > function], I need that mainFunction return at the end the same value
    > > of calling() execution [returnValue]. How can I do It?

    >
    > You can't. Since your HTTP request is handled asynchronously (as indicated
    > by the `true' value as third argument of XHR::eek:pen()), the execution context
    > of mainFunction() is probably left before the event listener is called.
    >
    > What *exactly* are you trying to do?
    >
    > PointedEars
    > --
    > Use any version of Microsoft Frontpage to create your site.
    > (This won't prevent people from viewing your source, but no one
    > will want to steal it.)
    > -- from <http://www.vortex-webdesign.com/help/hidesource.htm>


    then. through mainFunction() i call calling(), this is raised up by
    onkeyup on an input box. I do this sort of thing 3 times, username,
    password and email field. I need to understand return of these 3
    function calling, so I can understand if realize the form action or
    show an error.
     
    Mariano, Jan 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Dixson
    Replies:
    1
    Views:
    548
    Joe Fallon
    May 18, 2004
  2. Greenhorn
    Replies:
    15
    Views:
    887
    Keith Thompson
    Mar 6, 2005
  3. Chris Rebert
    Replies:
    1
    Views:
    728
    Bobby
    May 28, 2009
  4. DonaldN
    Replies:
    1
    Views:
    584
    Josh Twist
    Feb 17, 2006
  5. Kelly Dwight Felkins
    Replies:
    6
    Views:
    156
    Jeremy Henty
    Feb 9, 2006
Loading...

Share This Page