$ .ajax()不提供从静态json文件获取json的请求

时间:2015-08-10 11:35:27

标签: javascript php jquery ajax json

我正在尝试从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);
      }
});  

提前致谢! ..;(

1 个答案:

答案 0 :(得分:4)

$ .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);
    }
});