/ Published in: JavaScript

Simply replaces the div's innerHTML with the response text received from the file.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/*Executed on click. Passes the url to the function. Function opens the URL then *the parseResponse function is called */ function grabFile(file) { var request = getHTTPObject(); request.onreadystatechange = function() { parseResponse(request);//this is what happens once complete } request.open("GET",file,true); request.send(null); } /*Once the request state is complete and the file exists, it grabs the results * div, and inserts the response text and innerHTML. */ function parseResponse(request) { if(request.readyState == 4){ if(request.status == 200 || request.status == 304){ var results = document.getElementById("results"); results.innerHTML = request.responseText; } else { alert("Something Broke!"); } } }
Comments
