开发者

Jquery Ajax success not being called

开发者 https://www.devze.com 2023-03-12 17:16 出处:网络
Ajax call works, and deletes the file via unlink, however success is not called. I\'m using this same exact ajax function elsewhere, only it is with the .cli开发者_StackOverflow社区ck() event, not .li

Ajax call works, and deletes the file via unlink, however success is not called. I'm using this same exact ajax function elsewhere, only it is with the .cli开发者_StackOverflow社区ck() event, not .live(). Could that be the issue?

$('.picture_delete').live("click", function() {

$.ajax({

url: 'UrlWithArguments,

  async: false,
  success: function () {
      alert("YAY!");              
  } 

});//json });

This is the only relevant line of code being executed:

unlink($deleteMe);


The success() function is normally called when a 200 response code is returned. Does your PHP code complete the request, or does it hang?

Have you tried using Firebug, etc. to see what the response looks like from your PHP file?


First you should check whether the onclick event is triggered:

$('.picture_delete').live('click', function() {

  console.log('onclick event triggered'); //  or you can do: alert('onclick event triggered');

  $.ajax({
    url: 'UrlWithArguments',
    async: false,
    success: function () {
      alert('YAY!');              
    } 
  });
});

If the onclick event is triggered you should check whether the ajax call succeeds or fails:

$('.picture_delete').live('click', function() {
  $.ajax({
    url: 'UrlWithArguments',
    async: false,
    error: function(jqXHR, textStatus, errorThrown) {
      console.log('AJAX call failed: '+textStatus+' '+errorThrown); //  or you can do: alert('AJAX call failed: '+textStatus+' '+errorThrown');
    },
    success: function () {
      alert('YAY!');              
    } 
  });
});
0

精彩评论

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