Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - Read data back from URL
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Read data back from URL

 Post Reply Post Reply
Author
lee2121 View Drop Down
Newbie
Newbie
Avatar

Joined: 13 January 2017
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote lee2121 Quote  Post ReplyReply Direct Link To This Post Topic: Read data back from URL
    Posted: 13 January 2017 at 3:03pm
Hello, If i run the following code in an ASP page it loads the file (stored on local server) and outputs the text as expected;

<p id="demo"></p>

<button type="button" onclick="loadDoc()">Load Feed</button>

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "XML_TEST.xml", true);
  xhttp.send();
}
</script>

I need to run this from a URL not a local file. The URL has the exact same data and if i run the URL in a browser i get the data displayed in XML in the browser but when i change my code to fetch the data from the URL nothing happens.

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "https://test.httpapi.com/api/domains/available.xml?auth-userid=user&api-key=key&domain-name=domain&domain-name=domain2&tlds=com&tlds=co.uk", true);
  xhttp.send();
}
</script>

any ideas please how i can get this to work?
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9791
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 16 January 2017 at 10:46am
This looks to be JavaScript running client side rather than ASP code which would run server side.

Browsers often block client side JavaScript from running cross domain for security to prevent XSS vulnerabilities.

In addition running client side as JavaScript would expose your login credentials to the end user.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.