Jquery Ajax未调用成功

时间:2022-09-15 12:05:48

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 .click() event, not .live(). Could that be the issue?

Ajax调用可以工作,并通过unlink删除文件,但是不会调用success。我在其他地方也使用了相同的ajax函数,只是使用了.click()事件,而不是.live()。这是问题所在吗?

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

$(' .picture_delete ')。生活(“点击”,函数(){ $ . ajax({

url: 'UrlWithArguments,

url:‘UrlWithArguments,

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

});//json });

});/ / json });

This is the only relevant line of code being executed:

这是执行的唯一相关代码行:

unlink($deleteMe);

分离($ deleteMe);

2 个解决方案

#1


2  

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

success()函数通常在返回200个响应代码时调用。您的PHP代码是完成请求,还是挂起?

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

您是否尝试过使用Firebug等查看PHP文件的响应?

#2


1  

First you should check whether the onclick event is triggered:

首先要检查onclick事件是否被触发:

$('.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:

如果onclick事件被触发,您应该检查ajax调用成功与否:

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

#1


2  

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

success()函数通常在返回200个响应代码时调用。您的PHP代码是完成请求,还是挂起?

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

您是否尝试过使用Firebug等查看PHP文件的响应?

#2


1  

First you should check whether the onclick event is triggered:

首先要检查onclick事件是否被触发:

$('.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:

如果onclick事件被触发,您应该检查ajax调用成功与否:

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