SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)

    The frustration: Removing a XML file that has been parsed via Ajax?

    Hello all,

    I'm very new to JavaScript and am having some difficulties comprehending how to remove an XML file that I have parsed.

    My goal is to be able to add n number of XML files and have the ability to remove a parsed file. So, my question is, how can I remove the file I have just parsed?

    Any help would be much appreciated. Thanks in advance!

    kohoutek

    Here is the script:
    Code JavaScript:
    function getHTTPObject() {
      var xhr = false;
      if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        try {
          xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
          try {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
            xhr = false;
          }
        }
      }
      return xhr;
    }
     
    function grabFile(file) {
      var request = getHTTPObject();
      if (request) {
        request.onreadystatechange = function() {
          parseResponse(request);
        };
        request.open("GET", file, true);
        request.send(null);
     
      }
     
    }
     
    function parseResponse(request) {
      if (request.readyState == 4) {
        if (request.status == 200 || request.status == 304) {
          var data = request.responseXML;
          var name = data.getElementsByTagName("name")[0].firstChild.nodeValue;
          var image = data.getElementsByTagName("image")[0].firstChild.nodeValue;
          var remove = data.getElementsByTagName("remove")[0].firstChild.nodeValue;
          var header = document.createElement("h2");
          var text = document.createTextNode(name);
          var link = document.createElement("img");
          link.setAttribute("src",image);
          var linktext = document.createTextNode(image);
          link.appendChild(linktext);
          var details = document.getElementById("details");
          while (details.hasChildNodes()) {
            details.removeChild(details.lastChild);
          }
          details.appendChild(header);
          details.appendChild(link);
        }
      }
    }

    My XML file looks like this:

    Code XML:
    <?xml version="1.0" encoding="utf-8"?>
    <details>
      <name>Bea Sunglow</name>
      <image>http://myurl/images/BeaSunglowSmall.jpg</image>
     
    </details>

    Consequently, my HTML file looks like this:

    Code HTML4Strict:
    <!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" xml:lang="en" lang="en">  <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>Parse XML via Ajax</title>
      <style type="text/css">
      @import url("master.css");
      </style>
      <script type="text/javascript" src="fetchxml.js"></script>
    </head>
    <body>
      <h1>People</h1>
      <ul>
          <a href="files/beaSunglow.xml"
    onclick="grabFile(this.href); return false;">Bea Sunglow</a><a href="files/beaSunglow.xml">remove</a>
        </li>
      </ul>
      <div id="details"></div>
    </body>
    </html>
    Maleika E. A. | Rockatee | Twitter | Dribbble



  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,017
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    remove

    AFAIK, it's not possible to have AJAX alone delete server files.
    I guess you could use a server-side script to perform the filesystem functions. But IMHO, using a database would be better suited for working with temporary information.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •