简体   繁体   中英

Ajax request with JQ gives an error in Chrome: “Failed to load resource”

My idea is to ping the server to know if there is an internet connection, if there is, it will navigate to MyPage.html, if not it will show an alert.

Nevertheless, it seems that Chrome does not download the ping file to my PC and I get the error "Failed to load resource: net".

Why is this failing? This is just a plain text file.

(The file exists and I can see its content using its URL path perfectly. The file is located in the same directory as the script, so there are not cross domains issues).

Is there something related to my server?

Thanks

function ShowURL(){

$.ajax({
    url:'ping.txt',
    DataType:'text',
    cache: false,
    success: function (){
        window.location.href  = 'mypage.html';
    },
    error: function () {
        alert('Sorry, Internet conecction is required to perform this task');
    }
});

}

After hours and hours of try an Error I found the Answer: Dedicated for those guys who are facing the same problem:

In my case this was not a common Web Page, it was an Offline Web Page with a Manifest File.

Simply in the section "NETWORK" of the manifest file include the file "ping.txt"

Tha's all folks!

You should use: contentType:'text/plain' instead of DataType:'text'

You could just ask the browser if it was online through: navigator.onLine it returns a boolean. This doesn't require your server to be online for the client to be online :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM