简体   繁体   中英

using ajax to get local text file content

I have 2 files named index.html and mytext.txt in the same folder. I want to get contents of mytext.txt using an ajax call in the index.html . I use this code but it is only working in firefox not chrome:

$.ajax({
    url: "mytext.txt",
    dataType: 'text',
    success: function(data) {
        alert(data);
    }
});

I am opening index.html simply from explorer not server!

由于跨源政策,我认为您必须启动网络服务器才能在chrome中工作

Refer

Link 1

Link2

var file = Components.classes["@mozilla.org/file/local;1"].
   createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");

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