Sunday, 15 June 2014

php - Creating a button that deletes data being displayed -



php - Creating a button that deletes data being displayed -

right have programme uses ajax read in xml file , json file. problem 1 time user clicks 1 of these buttons text stays on page forever. wondering if there way create button delete text , sort of start over. tried making reset button didn't work. here code have. help in advance.

<!doctype html> <html> <head> <title>assignment8</title> <script src="ajax.js"></script> <script> function getxml() { var xmlhttp = xmlhttpobjcreate(); if (!xmlhttp) { alert("the browser doesn't back upwards action."); return; } xmlhttp.onload = function() { if (xmlhttp.status == 200) { // xml document var xmldoc = xmlhttp.responsexml; // variable our output var output = ''; // build output parsing xml dinos = xmldoc.getelementsbytagname('title'); (i = 0; < dinos.length; i++) { output += dinos[i].childnodes[0].nodevalue + "<br>"; } // div object var divobj = document.getelementbyid('dinoxml'); // set div's innerhtml divobj.innerhtml = output; } } xmlhttp.open("get", "dino.xml", true); xmlhttp.overridemimetype("text/xml") xmlhttp.send(); } function getjson() { var xmlhttp = xmlhttpobjcreate(); if (!xmlhttp) { alert("the browser doesn't back upwards action."); return; } xmlhttp.onload = function() { if (xmlhttp.status == 200) { // response text var response = xmlhttp.responsetext; // prints json string console.dir(response); // div object var divobj = document.getelementbyid('dinojson'); // used json.parse turn json string object var responseobject = json.parse(response); // our object console.dir(responseobject) // can utilize object so: (i in responseobject) { divobj.innerhtml += "<p>" + responseobject[i].name + " lived during " + responseobject[i].pet + " period.</p>"; } } } xmlhttp.open("get", "json.php", true); xmlhttp.send(); } </script> </head> <body> <form> <h3>dinosaur web services</h3> <div id="home"></div> <button type="reset" value="reset">home</button> <div id="dinojson"></div> <button type="button" onclick="getjson();">json dinos</button> <div id="dinoxml"></div> <button type="button" onclick="getxml();">xml dinos</button> </form> </body> </html>

you can empty div before inserting new value in it. below have done 1 of div, , same can other. add together script

<script> function reset() { var divobj = document.getelementbyid('dinoxml'); // set div's innerhtml divobj.innerhtml = ""; // empty div here divobj.innerhtml = output; } </script>

and add together button in html reset

php html xml json

No comments:

Post a Comment