And why not...
var url = "the url of the page containing the source you want";var http_request = false;if (window.XMLHttpRequest) { // Mozilla, Safari, and othershttp_request = new XMLHttpRequest();if (http_request.overrideMimeType) {http_request.overrideMimeType('text/xml'); //Mozilla browsers}} else if (window.ActiveXObject) { // IEtry {http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {http_request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}else {// Code to execute if the browser doesn't support XMLHttpRequest}if (!http_request) {// Code to execute if http_request is false (meaning it hasn't transformed in XMLHttpRequest nor in ActiveXObject)return false;}http_request.onreadystatechange = function() { functiontoexecute(http_request); };http_request.open('GET', url , true);http_request.responseType = "document" //necessary when it is not an XML document but a HTML one.http_request.send(null);function functiontoexecute(http_request) {if (http_request.readyState == 4) {if (http_request.status == 200) { //Example function if everything goes wellvar htmldoc = http_request.responseXML;var alertcontent = htmldoc.getElementById('idname').innerHTML;alert(alertcontent);} else {// Code if there has been an error (404 or other)}}}
The only real problem is that this is not very compatible. Chrome 18+, IE 10+, Firefox 11+, no Opera, no Safari, Firefox Mobile 11+, no other mobile browsers... Source: https://developer.mo..._XMLHttpRequest