【问题标题】:Abort Ajax Request in other function在其他函数中中止 Ajax 请求
【发布时间】:2015-09-15 12:51:44
【问题描述】:

我想中止另一个函数中的 Ajax 请求 示例:

var xhr = false;
$(function(e) {
     $(document).on('click', '.menue-button', function(e) {
         // Some JS
         xhr = $.ajax({
             type: "POST",
             url: index.php,
             //The ajax functions
          });
      });
});

$(document).on('click', '#progress-abort', function() {         
    xhr.abort();
});

调试器说:

Uncaught TypeError: Cannot read property 'abort' of undefined

我知道为什么,但我不知道如何解决问题

【问题讨论】:

    标签: jquery ajax abort


    【解决方案1】:

    它尝试了以下方法:

    var xhr = false;
    $(function(e) {
     $(document).on('click', '.menue-button', function(e) {
         // Some JS
         xhr = $.ajax({
             type: "POST",
             url: index.php,
             //The ajax functions
          });
      $(document).on('click', '#progress-abort1', function() {
        xhr.abort();
      });
    
      $(document).on('click', '#progress-abort', function() {         
          $('#progress-abort1').trigger('click');
      });
    });
    

    '#progress-abort1 不会触发。怎么了?

    【讨论】:

      猜你喜欢
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多