帮助我的jQuery ajax成功函数不会触发

时间:2022-10-02 21:12:16

I have a JS function that does a ajax GET (datatype: JSON) to a PHP page on the same domain.

我有一个JS函数,它对同一域上的PHP页面执行ajax GET(数据类型:JSON)。

I get the JSON response as I can see it via firebug but my success function doesn't seem to execute.

我得到了JSON响应,因为我可以通过firebug看到它,但我的成功函数似乎没有执行。

function getAppointments(){
var url = "http://site.com/quote/appointments/download/";

    $.ajax({
     type: "GET",
     dataType:"json",
     url: url,

     success: function(data, textStatus, jqXHR) 
    {
       alert('success');
       $.each(data,function() 
       {
          var li = $('<li />'); 
          li.val(); //haven't gotten this far yet
          li.text();
          $('#appointment-list').append(li); 
       });
    }

  });

}

}

I get a 200 OK status in firebug and can see the json objects but my alert('success') doesn't fire.

我在firebug中获得200 OK状态并且可以看到json对象,但我的警报(“成功”)不会触发。

Can anyone see why? I'm sure it's just a little mistake somewhere.

谁能明白为什么?我确定这只是某个地方的一个小错误。

Regards,

问候,

Billy

比利

2 个解决方案

#1


1  

Are you sending the correct headers from PHP? If you are sending JSON you should include:

你从PHP发送正确的标题?如果您要发送JSON,则应包括:

header('Content-type: application/json');

To tell whatever opens the script that it is JSON.

告诉任何事情打开脚本它是JSON。

#2


0  

try using $.getJSON("http://site.com/quote/appointments/download/", function() {

尝试使用$ .getJSON(“http://site.com/quote/appointments/download/”,function(){

#1


1  

Are you sending the correct headers from PHP? If you are sending JSON you should include:

你从PHP发送正确的标题?如果您要发送JSON,则应包括:

header('Content-type: application/json');

To tell whatever opens the script that it is JSON.

告诉任何事情打开脚本它是JSON。

#2


0  

try using $.getJSON("http://site.com/quote/appointments/download/", function() {

尝试使用$ .getJSON(“http://site.com/quote/appointments/download/”,function(){