jQuery 点击和加载功能不起作用

jQuery click and load function do not work

我正在尝试使用以下代码将文本从 txt 文档加载到 div:

$(document).ready(function(){
    $('button').click(function(){
        $('#contenthere').load('Load.txt');
    });
});

html:

<button> click me! </button>
<div id="contenthere">//Load.txt should load here!</div>

txt:

If this text is loaded then you've managed to succefully use jQuery!

点击功能正常,但加载功能根本不工作,我尝试了不同的方法来解决这个问题,但没有成功,Load.txt 文件与索引文件位于同一文件夹中jquery 加载代码已存储!

编辑: 这是我得到的错误:

XMLHttpRequest cannot load file:///C:/Users/nti/Google%20Drive/Gr%C3%A4nssnittsdesign/slutUppgift/exempel/Load.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

我也试过:

$(document).ready(function(){
    $('button').click(function(){
        $.ajax({
            url: "Load.txt",
            dataType: "text",
            succes : function (data){
                $("#contenthere").html(data);
            }
        });
    });
});

得到了和上面一样的错误。

我让代码工作,问题一定是我尝试使用 file:// 而不是 http:// 所以我将页面加载到 Webb 主机并让代码工作!