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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    issue with javascript...

    PHP Code:
    function xmlhttp() {
        if (
    window.XMLHttpRequest) {
            
    xmlhttp=new XMLHttpRequest();
        }
        else {
            
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return 
    xmlhttp;

    Calling on the http variable more than once causes an error, so the xmlhttp function is being called twice. Why is it causing an error? Wouldn't it just be the same?

    PHP Code:
    function load_dialog(dialog) {
        
    doc('blackout').style.visibility "visible";
        
    doc('dialog').style.visibility "visible";
        var 
    http xmlhttp();
    ... 

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You can't name a variable the same as a function name.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    martynball (05-15-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    The function name is "xmlhttp" and the variable is "http". It's different?

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 Posts
    Quote Originally Posted by martynball View Post


    Calling on the http variable more than once causes an error, so the xmlhttp function is being called twice. Why is it causing an error? Wouldn't it just be the same?
    run this ...

    function xmlhttp() {
    if (
    window.XMLHttpRequest
    ) {
    xmlhttp=new XMLHttpRequest
    ();
    }
    else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"
    );
    }
    return
    xmlhttp
    ;
    }


    xmlhttp()
    alert(xmlhttp) // xmlhttp now equals the XMLHttpRequest objest


  • #5
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    You use the variable xmlhttp for a function, but in this function you overwrite this variable with a XMLHttpRequest object, so when you assign the http variable the second time, the xmlhttp variable holds the XMLHttpRequest object returned by the function, not the function itself.

  • Users who have thanked oneguy for this post:

    martynball (05-15-2013)

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    oneguy beat me to it.

    You're killing the function by naming a variable inside the function with the same name as the function.

    Code:
    function abstract(){
      var abstract = "kill the function";
      }
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    martynball (05-15-2013)

  • #7
    New Coder
    Join Date
    Jul 2012
    Location
    Ukraine
    Posts
    71
    Thanks
    1
    Thanked 18 Times in 17 Posts
    WolfShade, no, in this example you just create a local variable abstract that hides the global function abstract inside this function. It should be without "var".

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Can you show us the full code that doesn't work??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Quote Originally Posted by WolfShade View Post
    oneguy beat me to it.

    You're killing the function by naming a variable inside the function with the same name as the function.

    Code:
    function abstract(){
      var abstract = "kill the function";
      }
    Ah yeah I see now, that makes sense. Thanks, I changed the code and now it works


  •  

    Posting Permissions

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