Search code examples
htmliisxmlhttprequestipwindows-server-2012-r2

XHR works on localhost server but not on my static IP on IIS


I am using IIS on my Windows Server 2012 R2 program. I have a static IP, and I've binded it to a port and enabled port forwarding so it is accessible online. Here's the thing, on localhost my XHR request produces the desired output. But when I search my static IP in the URL, and attempt the request, it does not produce anything. Here are the files:

<!DOCTYPE html>
<html>
<body>

<h1>The XMLHttpRequest Object</h1>

<button type="button" onclick="loadDoc()">Request data</button>

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


<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", "demo_get.txt", true);
  xhttp.send();
}
</script>

</body>
</html>

And here's my desired output "demo_get.txt":

<p>This Content was requested using the GET method.</p>

So can someone please guide me in making my XHR request functional when I enter my Static IP into the url? Thanks.


Solution

  • As suggested by others, I went into the Developer Tools and found that no request was being sent on the Network Tab. So, I investigated my security settings on my local intranet. I enabled some settings, and that's all it took for the XHR requests to function. Thank you everyone for your input!