AJax¼¼Êõ

Ajax ´ÓXMLµ½Éú³É±í¸ñ

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-03-25 16:01 ÎÒÒªÆÀÂÛ( )

ÏÂÃæͼÀÏʦС±à¸ú´ó¼Ò·ÖÏíAjax ´ÓXMLµ½Éú³É±í¸ñ£¬Ò»ÆðÀ´Ñ§Ï°Ï¹ý³Ì¾¿¾¹ÈçºÎ½øÐаɣ¡Ï²»¶¾Í¸Ï½ôÊÕ²ØÆðÀ´Å¶~

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
html xmlns="http://www.w3.org/1999/xhtml"
head
titleDynamically Editing Page Content/title
script. type="text/javascript"
var xmlHttp;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
function doSearch() {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", "dynamicContent.xml", true);
    xmlHttp.send(null);
}
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            clearPreviousResults();
            parseResults();
        }
    }
}
function clearPreviousResults() {
    var header = document.getElementById("header");
    if(header.hasChildNodes()) {
        header.removeChild(header.childNodes[0]);
    }
   var tableBody = document.getElementById("resultsBody");
    while(tableBody.childNodes.length 0) {
        tableBody.removeChild(tableBody.childNodes[0]);
    }
}
function parseResults() {
    var results = xmlHttp.responseXML;
    var property = null;
    var address = "";
    var price = "";
    var comments = "";
    var properties = results.getElementsByTagName("property");
    for(var i = 0; i properties.length; i++) {
        property = properties[i];
        address = property.getElementsByTagName("address")[0].firstChild.nodeValue;
        price = property.getElementsByTagName("price")[0].firstChild.nodeValue;
        comments = property.getElementsByTagName("comments")[0].firstChild.nodeValue;
        addTableRow(address, price, comments);
    }
    var header = document.createElement("h2");
    var headerText = document.createTextNode("Results:");
    header.appendChild(headerText);
    document.getElementById("header").appendChild(header);
    document.getElementById("resultsTable").setAttribute("border", "1");
}
function addTableRow(address, price, comments) {
    var row = document.createElement("tr");
    var cell = createCellWithText(address);
    row.appendChild(cell);
    cell = createCellWithText(price);
    row.appendChild(cell);
    cell = createCellWithText(comments);
    row.appendChild(cell);
    document.getElementById("resultsBody").appendChild(row);
}
function createCellWithText(text) {
    var cell = document.createElement("td");
    var textNode = document.createTextNode(text);
    cell.appendChild(textNode);
    return cell;
}
/script
/head
body
form
    input type="button" value="Search" nclick="doSearch();"/   
/form
span
/span
table
    tbody
    /tbody
/table
/body
/html

À´Ô´:

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ±àд¸ßЧµÄjQuery´úÂë¼¼ÇÉ×ܽá

    ±àд¸ßЧµÄjQuery´úÂë¼¼ÇÉ×ܽá

    2017-03-01 13:04

  • .NETÖÐweb¿ª·¢¼¼ÊõµÄиïÃü£¨ASP.NET2.0£¬AJAX,Silverlight£©

    .NETÖÐweb¿ª·¢¼¼ÊõµÄиïÃü£¨ASP.NET2.0£¬AJAX,Silverlight£©

    2017-02-09 16:00

  • Web¿ª·¢£º·ÖÒ³¼¼ÊõµÄʵÏÖ£¨ÉÏ£©¡ª¡ªjBootstrapPage.js+ajax

    Web¿ª·¢£º·ÖÒ³¼¼ÊõµÄʵÏÖ£¨ÉÏ£©¡ª¡ªjBootstrapPage.js+ajax

    2017-01-03 17:01

  • 10¿îʵÓõÄAjax/JavaScript±àÂ빤¾ßÍƼö

    10¿îʵÓõÄAjax/JavaScript±àÂ빤¾ßÍƼö

    2016-08-10 12:00

ÍøÓѵãÆÀ
Á