我正在尝试从 xampp 服务器上的静态 .json 文件中获取 json 数据。我可以用 getJSON 做同样的事情,但不能用 $.ajax() 做。有人可以指出错误吗?
$.ajax(function(){
type: 'POST',
url: 'http://localhost/example3/data.json',
data: { patientID: "1" },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(jsonData) {
alert(jsonData);
},
error: function() {
alert('Error loading PatientID=' + id);
}
});
提前致谢! .. ;(
最佳答案
$.ajax 的第一个参数不是函数。 只需在下面给出
$.ajax({
type: 'POST',
url: 'http://fin.qfun.kr/index/a2',
data: { patientID: "1" },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(jsonData) {
alert(jsonData);
},
error: function() {
alert('Error loading PatientID=' + id);
}
});
关于javascript - $.ajax() 不提供从静态 json 文件获取 json 的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918506/