jQuery.ajax()。中止()_浏览器仍然接收数据? [英] jQuery.ajax().abort() _ browser still receives the data?

查看:117
本文介绍了jQuery.ajax()。中止()_浏览器仍然接收数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery的,如果我放弃Ajax调用,它是由全浏览器加载,然后从内存转储,而不是事件处理?或者,只是头装?在一个更复杂的脚本,我注意到,有时所有的数据被接收之前标记为中止在Firefox / Firebug的。

JavaScript的:

 变量$ AJAX;
函数取(){
如果($阿贾克斯和放大器;&安培;!$ ajax.status code = 200)$ ajax.abort();
$阿贾克斯= $阿贾克斯({
    输入:'得到',
    数据:{搜索:术语},
    数据类型:JSON,
    网址:HTTP://localhost/data.php,
    成功:函数(_data){},
});
}

取();
取();
 

data.php:

 打印小睡!;
睡眠(2);
 

解决方案

解决在评论!由于ZeSimon

  

也许您正在使用本地主机,以便转移将要很快涉及到的事实。而事实上,你不加载大量数据。此外,通过的时候,你已经收到了回应code。在本地主机环境的要求就已经完成了。你需要更多的数据,并在多条生产般的环境进行测试。 - ZeSimon

In jQuery, if I abort an ajax call, is it loaded by the browser in full, and then dumped from memory and not event-handled? Or are just the headers loaded? In a more complex script I'm noticing that sometimes all the data is received before marked as aborted in Firefox/Firebug.

javascript:

var $ajax;
function fetch(){
if ($ajax && $ajax.statusCode != 200) $ajax.abort();
$ajax = $.ajax({
    type: 'get',
    data:{search:"term"},
    dataType: 'json',
    url: 'http://localhost/data.php',
    success: function(_data){ },
});
}

fetch();
fetch();

data.php:

print 'naptime!';
sleep(2);

解决方案

Resolved in comments! Thanks ZeSimon

Possibly related to the fact that you are using localhost so transfers are going to very quick. And the fact that you are not loading much data. Also, by the time you have received the response code in your localhost environment the request would already be complete. You need to test this with more data and in a more production like environment. – ZeSimon

这篇关于jQuery.ajax()。中止()_浏览器仍然接收数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆