Robert
Robert

Reputation: 686

$.ajax failing when trying to load html file

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);
    }
})

Upvotes: 2

Views: 53

Answers (1)

Malcolm McSwain
Malcolm McSwain

Reputation: 1948

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",

Upvotes: 1

Related Questions