doudou890510 2012-07-27 02:40
浏览 36
已采纳

在调用相同的函数时取消Ajax调用

I have a function:

function modifydata(what) {
    $.post(somepage.php+"?url="+replacedurl+"&userDesc="+userdesc+"&submitType="+what, {

    }, function(response){
        alert(response)
    });
}

I call the same function on two links link1, link2.

When the user clicks on link1 and the ajax is still processing, and if the user clicks link2 at the same time which calls the same function but with different values I'd like to shut the first processing to avoid load issues. Can it be possible without having the create the same function with a different name? If so, how?

  • 写回答

1条回答 默认 最新

  • dpf25323 2012-07-27 02:45
    关注

    Store the previous XHR in a static variable, and abort if the value isn't null and then set to null when the XHR is done.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上