简体   繁体   中英

How to post in HTML using Ajax

My code so far is

    <script type="text/javascript">
    var xmlDoc;
    var xmlhttp;
    function loadRates() {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = readRates;
        xmlhttp.open("GET", "PartialRates.xml", true);
        xmlhttp.send();
    }

    function readRates() {
        if (xmlhttp.readyState == 4) {

            xmlDoc = xmlhttp.responseXML;
            var rateRows = xmlDoc.getElementsByTagName("countryRates");
            var totAttributes = rateRows[0].attributes.length;

How do I get information from my PartialRates.xml onto my HTML? I need to post simple rates on my HTML.

My XML looks like this:

<PartialRates>
<countryRates
rate1="CampusSupport@html.edu"
rate2="1-800-588-7886"
rate3="TechnicalSupport@html.edu"
rate4="1-800-588-7885">
</countryRates>
</PartialRates>

rate1,rate3,rate5 all emails and rate2,rate4 are all phone numbers?

here is some idea you can follow and finish it; i had to change to html tag source. you can use your xml setting

var xmldata =document.getElementById("xmldata").innerHTML;

var turnArray=xmldata.split("rate");

for(var i=0; i<turnArray.length; i++) {
    if((i%2) == 0) {

        console.log("phone" + turnArray[i])}
    else
        {
            console.log("email" + turnArray[i])
        }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM