3

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?

4
  • 2
    "But I do not know how to write it in javascript" That is writing it in JavaScript. What you're really asking is how to do it without jQuery, just using the APIs built into the browser (the DOM and XMLHttpRequest). Commented Mar 25, 2015 at 10:07
  • Yes, I do not want to use it with jQuery Commented Mar 25, 2015 at 10:08
  • Well, where are you stuck? What research have you done? What does your attempt to do it look like? Commented Mar 25, 2015 at 10:11
  • Please see "Should questions include “tags” in their titles?", where the consensus is "no, they should not"! Commented Mar 25, 2015 at 10:25

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

2 Comments

I hope it helped you. Also, if you want to support old versions of IE then you can have a look at: This reference link
Does not work as it triggers the cross origin error blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.