// CSE 190 M, Spring 2008 (Marty Stepp) // JavaScript code for ASCIImation fetcher example // // This version of the program can also POST a new ASCII // art for a student back to the server. window.onload = function() { $("fetch").onclick = fetchClick; $("submit").onclick = submitClick; }; // Called when Submit is clicked. // Sends the current ASCII art text to the server as a POST request. function submitClick() { var lastName = $("lastname").value; var ascii = $("results").value; new Ajax.Request( "ascii.php", { method: "post", // optional parameters: { "name": lastName, "ascii": ascii }, onFailure: ajaxFailure } ); } // Called when Fetch is clicked. // Retrieves the current student's ASCII art. function fetchClick() { var lastName = $("lastname").value; if ($("xmlmode").checked) { // XML mode new Ajax.Request( "ascii.php?name=" + lastName + "&type=xml", { method: "get", onSuccess: ajaxXmlSuccess } ); } else { // plain text mode new Ajax.Request( "ascii.php?name=" + lastName, { method: "get", onSuccess: ajaxTextSuccess } ); } } function ajaxTextSuccess(ajax) { $("results").textContent = ajax.responseText; } function ajaxXmlSuccess(ajax) { // optional: remove previous children from list while ($("frames").childNodes.length > 0) { $("frames").firstChild.remove(); } var frameTags = ajax.responseXML.getElementsByTagName("frame"); for (var i = 0; i < frameTags.length; i++) { // add an