Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load external URL content using pure Javascript

Tags:

javascript

The following JQuery gets content of an external url:

var url = 'example.com/editor/stores/10';
$('#storeArticlePublish_Channel').load(url);

I do not want to use JQuery. How would I do this using normal javascript?

like image 450
vibol Avatar asked Dec 13 '25 16:12

vibol


1 Answers

You can use XMLHttpRequest object for this.To make a request:

var xmlhttp;
if (window.XMLHttpRequest)
{
  xmlhttp = new XMLHttpRequest();
}
xmlhttp.open("GET",URL,true);
xmlhttp.send();

The 'URL' is the url you want to execute/open. The 3rd parameter is for async request, it can be either true or false. And to get the result in #storeArticlePublish_Channel element, you can simply use this in the next line:

document.getElementById("storeArticlePublish_Channel").innerHTML = xmlhttp.responseText;
like image 144
Tushar Avatar answered Dec 15 '25 08:12

Tushar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!