Php 如何取消ajax调用

Php 如何取消ajax调用,php,jquery,ajax,solr,Php,Jquery,Ajax,Solr,我使用ajax函数将整个数据更新到solr中。它正在运行ok bt,我想添加一个取消按钮,这样用户就可以取消索引,这是我的代码 $(document).ready(function() { var callback=getQuerystringNameValue('auth_callback'); if(callback==1) { $('.loder').fadeIn('slow'); $.ajax({

我使用ajax函数将整个数据更新到solr中。它正在运行ok bt,我想添加一个取消按钮,这样用户就可以取消索引,这是我的代码

$(document).ready(function()
  {
    var callback=getQuerystringNameValue('auth_callback');
    if(callback==1)
    {
        $('.loder').fadeIn('slow');
        $.ajax({

                type:"post",
                url: 'auth.php',
                data: 'indexing=true',
                success: function(data) 
                {
                    $('.loder').fadeOut('slow');
                    window.location=<?php Home; ?> ;
                }
            });
    }

  });

if(isset($_POST['indexing']))
    {
     handle_dropbox_auth($dropbox);
        $user=$dropbox->GetAccountInfo();
         $user_id=$user->uid;
       handle_dropbox_auth($dropbox);
         $files = $dropbox->GetFiles();

       foreach ($files as $key => $value) 
        {

           if($value->is_dir!=1 && !in_array($value->mime_type, $restrict))
           {
               //print_r($value);

            index_into_solr($value,$dropbox,$client,$user_id);
           } 
       }

      }  
你可以试试下面的代码

var xhr = $.ajax({
    type:"post",
    url: 'auth.php',
    data: 'indexing=true',
    success: function(data) 
    {
        $('.loder').fadeOut('slow');
        window.location=<?php Home; ?> ;
    }
});
// Cancel button click
$('.btn-cancel').click(function(){
//kill the request
    xhr.abort();
})
var xhr=$.ajax({
类型:“post”,
url:'auth.php',
数据:'index=true',
成功:功能(数据)
{
$('.loder').fadeOut('slow');
window.location=;
}
});
//取消按钮单击
$('.btn cancel')。单击(函数(){
//终止请求
xhr.abort();
})

尝试使用.abort(),查看此项并单击。希望对您有所帮助。

做一个类似ajax的参考变量

var ajax=$.ajax({….})

并在需要时触发abort()

ajax.abort();
ajax.abort();