gpt4 book ai didi

jquery - 最简单的 jQuery .ajax 找不到 json 文件

转载 作者:行者123 更新时间:2023-12-01 06:36:24 28 4
gpt4 key购买 nike

我在 IIS 目录中托管了以下 jQuery:

$(function () {
$.ajax({
"url": "sample.json",
"type": "get",
"dataType": "json",
"success": function(data) {
console.log(data);
},
"error": function(jqXHR, status, error) {
console.log("status:",status, "error", error);
}
}) ;
});

当我浏览 html 文件时,我在 JS 控制台中得到以下内容:

GET http://localhost/Ajax/sample.json 404 (Not Found) jquery-1.9.0.min.js:3
status: error error Not Found app.js:18

它就在目录中。当我使用/sample.json 时,我得到:

GET http://localhost/sample.json 404 (Not Found) jquery-1.9.0.min.js:3
status: error error Not Found

如何让它找到本地文件并执行ajax调用?

最佳答案

由于这是 IIS,因此您可能会收到 404 错误的子类型,即 404.3 错误,原因是缺少 MIME 映射。 JSON 文件不会注册为 IIS 默认提供的服务。进入 INETMGR 并将扩展添加到您的 MIME 映射中。

(网站 — MIME 类型 — 添加 — json : application/json)

enter image description here

关于jquery - 最简单的 jQuery .ajax 找不到 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14819001/

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