+ 5

Javascript Html Request

How to get source code of a website or url entered. Is there any method for this? Please let me know for this.

19th Oct 2019, 2:06 AM
Ankit Yadav
Ankit Yadav - avatar
5 Answers
+ 1
You can use jQuery to make an AJAX request that gets the html from an external url. It would look something like this: $.ajax({ url: "external url here" }).done(html => { // Do stuff with html here. }); AJAX Information: http://api.jquery.com/jquery.ajax/
19th Oct 2019, 2:56 AM
Brian R
Brian R - avatar
+ 1
Brian R can u please add code reference
19th Oct 2019, 2:58 AM
Ankit Yadav
Ankit Yadav - avatar
+ 1
If you are talking about html code, simply press Ctrl+U and you can see them. But for server-side code you need to hack the server in some ways to download the script file instead of being executed (Do not ASK HOW, uncle Google knows all). If you want to do it programatically (grab HTML source code) here's how Using JS (vanilla precisely) function ajaxRequest(reqUrl) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { //Do something with the code(response, in fact) //Your response lies in this variable this.responseText; console.log(this.responseText); } else { // Handle error here, if something goes left } }; xhttp.open("POST", reqUrl, true); xhttp.send(); } //Calling it ajaxRequest('your/url/of/preference.ext'); //.php, html or whatever //Beware of *same origin policy*
19th Oct 2019, 7:33 AM
Baraka Mghumba
0
You can't get source code of a website if they are loading dynamically pages. Some websites are made like that. You can get source code even full website using a software which is available on Internet. But it converts full website to html source code.
19th Oct 2019, 5:52 AM
A͢J
A͢J - avatar
0
You will only get html code if you will open url and left click and click on inspect
15th May 2020, 3:59 PM
PANDEY DIPTI VRIJESH
PANDEY DIPTI VRIJESH - avatar