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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:41:10+00:00 2026-06-08T07:41:10+00:00

I have a javascript function that makes an http_request to a php file on

  • 0

I have a javascript function that makes an http_request to a php file on my server that generates an XML file (see output below). When the XML file is returned the same javascript function parses the XML (This is where my problem lies) and passes it to other functions; which do the bulk of the processing.

So far I’ve been unable to parse my XML document and I can’t quite figure out why.

XML

<Results><!--Root-->
  <Result_Set>
    <State>State</State>
    <Cities>
      <City>City 1</City>
      <City selected="true">City 2</City>
       ...ETC...
    </Cities>
    <Zipcodes>
       <Zipcode selected="true">Zipcode 1</Zipcode
       <Zipcode>Zipcode 2</Zipcode>
        ...ETC...
    </Zipcodes>
  </Result_Set>
</Results>

Javascript

function GetZipInfo(zipcode){
    var xmlhttp;
    var x,resultSet,state,cities,zipcodes

    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){  

            resultSet=xmlhttp.responseXML.documentElement.getElementsByTagName("Result_Set") //Function Crashes Here

            for(x=0;x<resultSet.length;x++){
                state=resultSet[x].getElementsByTagName("State")[0].nodeValue;
                cities=resultSet[x].getElementsByTagName("Cities");
                zipcodes=resultSet[x].getElementsByTagName("Zipcodes");

                selectState(state)
                xmlDropdown(cities, "City", "Cities")
                xmlDropdown(zipcodes, "Zipcode", "Zipcodes")
            }
        }
    }   
    xmlhttp.open("GET","GetZipInfo.php?Zipcode="+zipcode,true);
    xmlhttp.send();
}

I have never parsed an XML document in ANY language before, so I think it’s safe to say that I’m completely lost as to what’s wrong.

Thank you in advance!

EDIT: It turns out that my response is coming back as responseText instead of responseXML

responseText

I am using php to create the XML page:

header("Content-Type: text/plain");
//Create the DOM
echo $xmlDoc->saveXML()

Still unsure why it’s not returning as XML. Could it have something to do with echo $xmlDoc->saveXML()?

Edit: I agree with several comments that my problem is with my header in the XML file.
I added the line “alert(xmlhttp.responseText)” to my code. Which displays:

<?xml version="1.0"?>
<!--The Contents of my XML file-->

Does the encoding type need to be set for this to work correctly. And if so, how can I modify my PHP code (see above) to insert that encoding?

  • 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-08T07:41:12+00:00Added an answer on June 8, 2026 at 7:41 am

    The MIME type of your response should be text/xml, or something ending with +xml (RFC 3023).

    Also, you should add a XML declaration before the first line.

    And last, but not least, although getElementsByTagName is available on all elements in HTML documents, you should use document.getElementsByTagName in XML documents:

    var resultSet = xmlhttp.responseXML.getElementsByTagName("Result_Set");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Javascript function that sends username and password to php file through
I have a a link that calls a onmouseover javascript function that makes a
I have a javascript function that calls a generic function to make an ajax
I have a JavaScript function that should only run on specific pages on a
I have a JavaScript function that looks like this: function recalculateWhatIfCurrentRate(aEle, aChangedLabel, recordID, yearEndCurrentRate)
I have a javascript function that accepts a number and performs a mathematical operation
I have a javascript function that checks for a date range. Is there any
I have a javascript function that is being built to animate the collapse of
I have a javascript function that toggles the display for rows in a table.
I have a Javascript function that is called from the onchange method in a

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.