Answers for "javascript get page content by url"

0

javascript get page content by url

// Using jquery
function getContent(url) {
	return $.ajax({
		url,
   		method: "GET",
      	success: function(res) {
        	return res
        },
      	error: function(e) {
        	return e.message
        }
	})
}

// Using Core Javascript
function getContent(url){
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            return xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", url, false );
    xmlhttp.send();    
}
Posted by: Guest on August-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language