showing results for - "javascript get page content by url"
Kendrick
02 Mar 2020
1// Using jquery
2function getContent(url) {
3	return $.ajax({
4		url,
5   		method: "GET",
6      	success: function(res) {
7        	return res
8        },
9      	error: function(e) {
10        	return e.message
11        }
12	})
13}
14
15// Using Core Javascript
16function getContent(url){
17    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
18        xmlhttp=new XMLHttpRequest();
19    }
20    else {// code for IE6, IE5
21        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
22    }
23    xmlhttp.onreadystatechange=function() {
24        if (xmlhttp.readyState==4 && xmlhttp.status==200)
25        {
26            return xmlhttp.responseText;
27        }
28    }
29    xmlhttp.open("GET", url, false );
30    xmlhttp.send();    
31}