Skip to content

Instantly share code, notes, and snippets.

@pchatterjee
Created November 12, 2018 23:42
Show Gist options
  • Select an option

  • Save pchatterjee/b3e42df05b0c1ebe7ce5480850e141c2 to your computer and use it in GitHub Desktop.

Select an option

Save pchatterjee/b3e42df05b0c1ebe7ce5480850e141c2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>AJAX pull XML Example</title>
<style>
textarea {
outline: none;
resize: none;
width: 400px;
height: 400px;
}
</style>
<script>
var url;
// do AJAX - it ain't rocket science
function loadDoc(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("xml_text").innerHTML = this.responseText;
console.log(this.responseText);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function sendRequest(val) {
/* we would extend this function and
attach value of form input fields here
but for now.. */
url = 'curr' + val + '.php';
loadDoc(url);
}
</script>
</head>
<body>
<input type="radio" id="post" onclick='sendRequest("Post")'> Post
<input type="radio" id="put" onclick='sendRequest("Put")'> Put
<input type="radio" id="delete" onclick='sendRequest("Del")'> Delete
<p/>
<textarea id="xml_text"></textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment