/ Published in: JavaScript
I prefer to use jQuery but hey if you want to do it in JavaScript, then here you go. Maybe I will update this code soon and have a working example in JSfiddle.
Expand |
Embed | Plain Text
var aRequest; //Makes an AJAX request & checks which request current broswer supports. if (window.XMLHttpRequest){ aRequest = new XMLHttpRequest(); } else if (window.ActiveXObject){ aRequest = new ActiveXObject("Microsoft.XMLHTTP"); } //Deals with the request aRequest.onreadystatechange = function(){ //if request has completely finished. if (aRequest.readyState === 4 && xmlhttp.status===200){ //code for whatever you want to do with the data goes here. var requestedData = innerHTML=xmlhttp.responseText; console.log("Data:" + requestedData); } }; //change this to desired path. it can be xml, html, etc. this is for testing ajax in JSfiddle. aRequest.open("POST", "/echo/html/", true); //no, we do not need to send data back. aRequest.send();
You need to login to post a comment.
