vibol
vibol

Reputation: 352

Load external URL content using pure 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?

Upvotes: 3

Views: 11272

Answers (1)

Tushar
Tushar

Reputation: 179

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;

Upvotes: 5

Related Questions