开发者

jQuery::Ajax success never occurs

I have an ajax call in the head section of my index.html

$(function() {
  alert("Hello, World!");
  $.ajax({
    method: 'get',
    url : 'php/getRecord.php?color=red',
    dataType: "json",
    success: function (data) { 
        alert(data); 
    }  
  });
});

For some reason, that alert(data) never gets c开发者_如何学运维alled but the "Hello, World!" gets called. Am I doing something wrong? The PHP file does give me data when testing it directly.


You're probably getting an error somewhere.

Check the HTTP request in Firebug or Fiddler and make sure that it's doing what you expect.

Add an error: handler and see whether it gets fired.


Have you tried defining an error callback to see if there's a problem?

,error: function(XMLHttpRequest, textStatus, errorThrown) {
    alert(textStatus);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜