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

  • Home
  • SEARCH
  • 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 8239729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:14:40+00:00 2026-06-07T20:14:40+00:00

I have this code: function loadRegions() { var xmlhttp; if (window.XMLHttpRequest) {// code for

  • 0

I have this code:

function loadRegions()
{
    var xmlhttp;

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
           alert("Ready:"+xmlhttp.status);
           xmlDoc=xmlhttp.responseXML;
           x=xmlDoc.getElementsByTagName("region");
           alert(x[0]);
           alert(x[1]);
       }
   }

   var ctrcode = frm.elements['countrycode'];
   xmlhttp.open("GET","http://mydomain.gr/regionslist.php?countrycode="+ctrcode.value,true);
   xmlhttp.send();
}

I have a select item in my HTML and when someone selects an item then this function is called to get the regions of this country. I can see from my console that the request is done, but the response is never gotten. My onreadystatechange function is never called. When I delete xmlhttp.status==200 then the function is called but the xmlDoc object is null and xmlhttp.status==0. The URL I use works if I call it alone. Why does my onreadystatechange function not work and why does it not return status 200?

  • 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-07T20:14:42+00:00Added an answer on June 7, 2026 at 8:14 pm

    add this line before calling send() function:

    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    

    and also set onReadyStateChange function after calling open()

    reasons:
    1) The responseXML property represents the XML response when the complete HTTP response has been received (when readyState is 4), when the Content-Type header specifies the MIME (media) type as text/xml, application/xml, or ends in +xml. If the Content-Type header does not contain one of these media types, the responseXML value is null.
    2) After the initial response, all event listeners will be cleared. Call open() before setting an onreadystatechange listener.
    here is references of the first and the second reason

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

Sidebar

Related Questions

I have this code: function render_message(id) { var xmlHttp; xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4)
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I am new to asp.net. I have this code: function onSubmitForm() { var formDOMObj
Hi I have this JS CODE function openPopup(url) { var newElem = new Element(
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
I have this code: var obj = function (i) { this.a = i; this.init
I have this code var stats = { GetMetaData : function() { var url
i have seen this code: Function.prototype.bind = function (bind) { var self = this;
I have this code: function render(str) { var main = document.createElement('div'); with(main.style) { //style

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.