1

我正在使用 jquery 加载外部页面并将其显示在名为 View 的 DIV 中。

我有 2 个按钮 Go & Stop。

这是可行的,但是当我单击停止时,可能需要几秒钟。有什么办法让它立即停止?

$("#Go").click(function () { 
    $("#view").load("test.php");
    refreshId = setInterval(function() { 
    $("#view").load("test.php"); }, 1000);  
});


$("#Stop").click(function () { 
    clearInterval(refreshId); $("#view").stop(); 
    $.ajax({ url : 'new.php' });
} });

谢谢 :)

4

1 回答 1

0

你可以试试:

var xhr = $.ajax({
    type: "POST",
    url: "test.php",
    data: "name=John&location=Boston",
    success: function(msg){
      $("#view").html(msg);
    }
});

并停止通话:

//kill the request
xhr.abort()
于 2013-06-08T11:34:19.447 回答