【发布时间】:2013-09-19 06:30:51
【问题描述】:
我正在使用 ajax 调用将数据加载到我的应用程序中。它适用于这样的路径
../../DataSource/newJson.json
但它不适用于这样的路径。
C:\Users\acer\Desktop\NewJson.json
我进行了很多搜索,但没有找到任何适合我的问题的解决方案。 我正在使用以下代码从本地目录加载文件。
<button id="loadData">update new Json</button>
<input type="file" id="newJson" value="file" />
这是我的 ajax 调用:
$("#loadData")[0].onclick= function (e){
$.holdReady(true);
var request = $.ajax({
type: "GET",
dataType: 'json',
url: $("#newJson").val(),
success: function (data) {
alert('success')
},
error: function (data, dat1, error) {
alert(error)
}
});
};
任何建议都值得赞赏。
【问题讨论】:
-
("#loadData")[0].onclick = e => {如果是 JavaScript,那就是语法错误。 -
我已经更新了我的代码。
标签: javascript jquery ajax