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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:27:44+00:00 2026-06-11T01:27:44+00:00

My JavaScript function function B_modeWindow (id,cords) { loading(); var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new

  • 0

My JavaScript function

function B_modeWindow (id,cords) {  
    loading();

    var xmlhttp;

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

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {

            var cords = document.getElementById(cords)
            cords.innerHTML=xmlhttp.responseText;
            var xy = cords.split("x");          
            hideloading();
        }
    }

    xmlhttp.open("GET","processMapEdit.php?id="+id+"&x="+xy[0]+"&y="+xy[1],true);
    xmlhttp.send();
}

returns:

Uncaught ReferenceError: xy is not defined 

in:

xmlhttp.open("GET","processMapEdit.php?id="+id+"&x="+xy[0]+"&y="+xy[1],true);

It seems that xy is just not there, but it’s defined just 5 lines above! What is wrong here?

  • 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-11T01:27:46+00:00Added an answer on June 11, 2026 at 1:27 am

    xy is only defined in the scope of the anonymous function xmlhttp.onreadystatechange = function () { // valid scope of xy }. Thus, it’s not accessible outside of this anonymous function. Use the following instead:

    function B_modeWindow (id,cords) {  
        loading();
    
        var xmlhttp;
    
        if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();
        } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    
        var xy = cords.split("x"); 
    
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                var cordsElement = document.getElementById(cords);
                cordsElement.innerHTML=xmlhttp.responseText;      
                hideloading();
            }
        }
    
        xmlhttp.open("GET","processMapEdit.php?id="+id+"&x="+xy[0]+"&y="+xy[1],true);
        xmlhttp.send();
    }
    

    This way, the scope of xy is the function B_modeWindow instead of the anonynmous function.

    Also, note that even if you could access xy outside of the anonymous function (which you can’t), xy won’t be defined as well, since you are defining it only when the AJAX request completes, and you need to use it to actually make the AJAX call.

    Another suggestion is for you to use different variable names for cords. You are using it first to split its content by x, and then defining another cords variable to assign a DOM element. Although this works, it can be confusing.

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

Sidebar

Related Questions

Does anyone recognize this JavaScript function? function (E,F){ var D=F||window; var A=[]; for(var C=0,B=this.length;C<B;++C){
When using Firebug or some of the bookmarklets: javascript:(function(){var a=document.createElement(script);a.setAttribute(src,http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js);if(typeof jQuery==undefined){document.getElementsByTagName(head)[0].appendChild(a)}(function(){if(typeof jQuery==undefined){setTimeout(arguments.callee,100)}else{jQuery(*).one(click,function(d){jQuery(this)[0].scrollIntoView();for(var e=,c=jQuery(this)[0];c&&c.nodeType==1;c=c.parentNode){var b=jQuery(c.parentNode).children(c.tagName).index(c)+1;b>1?(b=[+b+]):(b=);e=/+c.tagName.toLowerCase()+b+e}window.location.hash=#xpath:+e;prompt('Twoje
I like to do this in JavaScript: function (a, b, c) { var foo
I have the following javascript function in my extension: function findPos(obj) { var curleft
I have the simple javascript function inside $(function() { ... }); body var uploader
I am new to JavaScript and just started learning window methods. I wanted to
The JavaScript function function tile(u,v, a,b,c,d) { var c0 = tileCorners[a].eval(u,v); var c1 =
function Add(a, b) { } If we call a javascript function like - onclick=Add(1)
There is a JavaScript function in html <script type=text/javascript> function someFunction(){ return <b>some text</b>;
I am having a JavaScript namespace say A={ CA: function() { this.B(); }, B:

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.