Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript return does not work

    Hello,

    I made a little code for my website but it doesn't work and I can't find out what the problem is.

    The problem is that the line return 2; does return undefined and not 2 as expected.

    I also tried to replace var xmlhttp2 = ''; for var xmlhttp2 = null; but it still not work.

    Does anyone know what is incorrect?

    Thanks in advance,

    PHP Code:
     function get_image(url)
        {
            var 
    xmlhttp2 '';
            
    xmlhttp2=GetXmlHttpObject()
            
    xmlhttp2.onreadystatechange=function()
            {
                if (
    xmlhttp2.readyState == 4)
                {
                    return 
    2;
                }
            };
            
    xmlhttp2.open("GET"'image_print.php?url=' urltrue);
            
    xmlhttp2.send(null);
            
            
    //return output;
            
        


  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by DaLi View Post
    Hello,

    I made a little code for my website but it doesn't work and I can't find out what the problem is.

    The problem is that the line return 2; does return undefined and not 2 as expected.

    I also tried to replace var xmlhttp2 = ''; for var xmlhttp2 = null; but it still not work.

    Does anyone know what is incorrect?

    Thanks in advance,

    PHP Code:
     function get_image(url)
        {
            var 
    xmlhttp2 '';
            
    xmlhttp2=GetXmlHttpObject()
            
    xmlhttp2.onreadystatechange=function()
            {
                if (
    xmlhttp2.readyState == 4)
                {
                    return 
    2;
                }
            };
            
    xmlhttp2.open("GET"'image_print.php?url=' urltrue);
            
    xmlhttp2.send(null);
            
            
    //return output;
            
        

    I'm sure that statement does work but you can't read it, at least not in the way you seem to expect.

    I don't think you entirely appreciate what's happening here, perhaps you should start reading:
    https://developer.mozilla.org/en/ajax/getting_started

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am requesting the function get_image to get a number from my database (via image_print.php).

    That was working.. but for debug reasons I set "return 2" to be sure that was not the issue.

    I hope this will explain something:

    Code:
    var image_number = get_image('http://www.testurl.com/'); // should be 2, but returns undefined..
    Do you have any idea? I'm lost in code :-(


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •