页面冻结了秒的时候阿贾克斯后工作结了、时候、页面、工作

由网友(新潮的)分享简介:当我使用jQuery的$。员额AJAX功能,页面冻结2-3秒,然后接收到的数据。冷冻时间可以改变依赖于接收到的数据。 如何prevent呢?编辑:$ C $词现在用的,它实际收到非常大的数据。$后(../ ajax_updates.php。{时间:LAST_UPDATE},功能(数据){如果(数据){如果(数据!=){...

当我使用jQuery的$。员额AJAX功能,页面冻结2-3秒,然后接收到的数据。冷冻时间可以改变依赖于接收到的数据。

如何prevent呢?

编辑:

$ C $词现在用的,它实际收到非常大的数据。

  $后(../ ajax_updates.php。{时间:LAST_UPDATE},功能(数据){
   如果(数据){
   如果(数据!=){
    $(#news_feed)prePEND($(数据).fadeIn('慢'));
    }
    }
    });
 
皇马外租天才踢出职业生涯最完美一季,欲弥补阿贾克斯最大真空

解决方案

如果您通过JavaScript加载大数据量,这是正常的,带来的问题就是,因为你的要求是同步这将使您的浏览器需要等待该请求结束之前做别的。 你需要让你的要求同步

P.S。使用$不用彷徨,而不是$。员额从服务器获取信息,在某些情况下 - 特别是如果你在Windows下code工作IIS,你会得到一个错误有关

P.S-1。它是有意义$不用彷徨是从服务器获取数据和$。员额是用于发送数据。

试试这个:

  $。ajaxSetup({
    异步:真
});

$获得(../ ajax_updates.php,{时间:LAST_UPDATE},功能(数据){
  如果(数据&安培;&放大器;数据=!){
    $(#news_feed)prePEND($(数据).fadeIn('慢'));
  }
});
 

When i use jquery's $.post ajax function, page freezes for 2-3 seconds and then data received. Freezing time can change depends on the data received.

How can i prevent this ?

EDIT:

COde i am using, it actually receives very large data

$.post("../ajax_updates.php", {  time: last_update }, function(data) { 
   if (data) {
   if (data != "") {
    $("#news_feed").prepend($(data).fadeIn('slow'));
    }
    }
    });

解决方案

If you load big amount of data through JavaScript this is normal, the problem is caused because your request is synchronous which will make your browser to wait this request to end before do anything else. You need to make your request asynchronous

P.S. Use $.get instead of $.post to get information from the server, in some cases - specially if you code work under Windows IIS you will get an error about that.

P.S-1. And it make sense $.get is for getting data from the server and $.post is for sending data.

Try this:

$.ajaxSetup({
    async: true
});

$.get("../ajax_updates.php", {  time: last_update }, function(data) { 
  if (data && data != "") {
    $("#news_feed").prepend($(data).fadeIn('slow'));
  }
});

阅读全文

相关推荐

最新文章