问题描述
无法在本地主机上运行本教程: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax1
can't get this tutorial working in localhost:http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax1
我的jquery.js文件具有以下代码:
my jquery.js file has the following code:
$(document).ready(function() {
// AJAX //
$("button").click(function() {
$("div").load('ajax.txt');
});
});
,而ajax.txt文件位于同一文件夹中,但未加载任何文件.可能是什么问题?
and the ajax.txt file is in the same folder, but no file is loaded.What could be the problem ?
推荐答案
load()函数开始在根目录中查找与ajax文件不同的文件.因此,使用上面的代码,文件ajax.txt应该位于根文件夹中.否则,请更改以下行:
The load() function starts looking for a file in a root directory not in the same as the ajax file is. So with a code above your file ajax.txt should be in root folder. Otherwise change following line:
$("div").load('ajax.txt');
收件人:
$("div").load('assets/js/ajax.txt');
或从站点根文件夹开始的任何文件夹树!
or whatever folder tree you have, starting from site root folder!
这篇关于jQuery ajax load()文件在localhost中不起作用-(w3scools.com jQuery AJAX示例教程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!