gpt4 book ai didi

javascript - 将 jQuery.get 与目录中的文件一起使用?

转载 作者:行者123 更新时间:2023-11-30 06:08:20 25 4
gpt4 key购买 nike

我正在使用 jQuery 编写一个仅在本地运行的简单实用程序。它将使用 jQuery.get 从文件列表中读取,然后将它们与一些元数据(位于单独的文件中)一起显示。图片和元文件位于 ../scored_images/*.[jpg|meta]

我可以使用 jQuery.get 加载文件列表(它在当前目录中),我可以加载图像并毫无问题地显示它们。但是,当我加载要显示的元文件时,jQuery.get 似乎默默地失败了。如果路径中没有 ../,我可以很好地加载它们。有没有办法解决此问题?

最佳答案

首先,引用自 jQuery docs ,

If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method or. As of jQuery 1.5, the .error() method of the jqXHR object returned by jQuery.get() is also available for error handling.

所以当你发出GET请求时,你应该加上:

$.get('url').error(function (jqXHR, textStatus, errorThrown) {
//handle error. this can help you find the problem.
}

除此之外,如果没有您提供的一些代码,我不能说更多。我试着按照你描述的去做(据我所知),它对我来说效果很好。我跑了:

$.get('../data/test.meta').success(function (data) {
$('#content').append(data);
});

来自此目录中的 index.html:

Directory

如果我有什么不明白的地方请告诉我,我会尽力提供更多帮助。

关于javascript - 将 jQuery.get 与目录中的文件一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2481861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com