ajax順序與async:true的選擇順序不匹配

[英]ajax order does not match selection order with async:true


I have this code which is called at an onChange event of an

我有一個在onChange事件中調用的代碼

function group_changed(obj)
{
  $.ajaxSetup({async:false});
  $.post("/medilab/personnel/groups/getGroupRightsAjax",
    { 'group.id': obj.options[obj.selectedIndex].value },
    function(data){
      $("#div_rights").html(data);
    }
  );
}

This works fine but if i set async:true sometimes the result doesnt match the selection... I guess that this is happening because some requests are lost or that the responses dont come in order.

這工作正常,但如果我設置async:true有時結果與選擇不匹配...我猜這是因為一些請求丟失或響應沒有按順序發生。

Any idea what to do to keep it asynchronous?

知道如何保持異步嗎?

3 个解决方案

#1


5  

There are a few plugins for jQuery that support queuing and ordering of the ajax requests. John Resig wrote Ajax Queue. From the plugin description:

有一些jQuery插件支持排隊和排序ajax請求。 John Resig寫了Ajax Queue。從插件描述:

Ajax Queue is a plugin that helps to manage Ajax race conditions. When multiple Ajax requests are made in rapid succession, the results can be returned out of order. This can cause weird behavior in your application.

Ajax Queue是一個有助於管理Ajax競爭條件的插件。當快速連續發出多個Ajax請求時,結果可能無序返回。這可能會導致您的應用程序出現奇怪的行為。

This sounds like it may be what you need, there should also be a couple different plugins available that accomplish the same thing (keeping ajax requests ordered). Ajax Manager looks to be more up-to-date. Browse through some of the plugins, you might find something that already does what you are looking to accomplish, saving you time.

這聽起來可能是你需要的,還應該有幾個不同的插件可以完成相同的事情(保持訂單的Ajax請求)。 Ajax Manager看起來更新。瀏覽一些插件,您可能會發現已經完成了您想要完成的任務,節省您的時間。

#2


1  

try this, it may be a better solution.

試試這個,這可能是一個更好的解決方案。

$.ajax
({
    type:'post',
    data:'',
    dataType: 'html',
    url: '',
    success: function(data) {
        alert('data');
    },
    error: function()   {
       alert("Error");
    }
});

#3


1  

Managers is a solution but i fixed my problem using abort()!

經理是一個解決方案,但我使用abort()解決了我的問題!


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/03/15/720ddf2a264f59c5b70ef44ae1da31dc.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com