2

I am trying to load part of an html file into another html file, but I keep getting the following error and the error function is running: enter image description here

Can anyone tell me what I'm doing wrong with my ajax call?

var application = slides.names[counter].replace(/ /g, "");
$.ajax({
    url: "games/" +application +"/index.html",
    dataType: "HTML",
    success: function(result, status, xhr){
        console.log(this.url);
        console.log(result);
        console.log(status);
        console.log(xhr);
    },
    error: function(result, status, xhr){
        console.log(this.url);
        console.log(result);
        console.log(status);
        console.log(xhr);
    }
})
Robert
  • 624
  • 2
  • 8
  • 19
  • 1
    Maybe this will help: [http://stackoverflow.com/questions/29006336/chrome-load-local-resource](http://stackoverflow.com/questions/29006336/chrome-load-local-resource) or this post: [http://stackoverflow.com/questions/7591840/load-local-xml-file-chrome-14](http://stackoverflow.com/questions/7591840/load-local-xml-file-chrome-14) – Martin Mar 01 '17 at 21:43
  • 5
    you are trying to perform an HTTP request to a local file, your error explicitly tells you what you're doing wrong :P – Ahmed Masud Mar 01 '17 at 21:43
  • 2
    You need a web server first. – dokgu Mar 01 '17 at 21:44
  • 1
    Have a look at this: http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local – Leo Farmer Mar 01 '17 at 21:45

1 Answers1

1

You can't request a local file using HTTP, since the protocol is meant for cross-origin requests.

You could solve this by installing a webserver locally with Apache (or some other local webserver): https://www.sitepoint.com/how-to-install-apache-on-windows/

Alternatively, you could upload the html files you are trying to access to some other location and access them through

url: "http://foo.com/" + application + "/index.html",
Malcolm McSwain
  • 1,888
  • 2
  • 15
  • 17