2012-07-10 109 views
0

我創建了一個非常昂貴的php類,需要在管理頁面上處理很多請求。由於這個原因,我試圖使用jquery queing + ajax調用來批量處理請求,但是整個javascript沒有解僱,我不明白爲什麼。我更喜歡js或jQuery的PHP專家。消息隊列+ ajax沒有觸發

的代碼:

<script type="text/javascript"> 
$(document).ready(function() { 
    window.queue = $.jqmq({ 
    // Queue items will be processed every 250 milliseconds. 
    delay: 500, 
    // Process queue items one-at-a-time. 
    batch: 10, 
    // For each queue item, execute this function. 
    callback: function (model, apit) { 
     $.ajax({ 
     url: 'script.php', 
     type: "post", 
     cache: false, 
     data: "model=" + model + "&api=" + apit, 
     success: function (data) { 
      $(".error_msg p").append(data); 
     } 
     }, 
     // When the queue completes naturally, execute this function. 
     complete: function() { 
     $.ajax({ 
      url: 'script.php', 
      type: "post", 
      cache: false, 
      data: "cleanup=1", 
      success: function (data) { 
      $(".error_msg p").append(data); 
      } 
      $('.error_msg p').append('<br /><span class="done">Queue done<\/span>'); 
     } 
     }); 
     //the next line is repeated a couple hundred times with different values 
     queue.add('arg1', 'arg2'); queue.add('arg1', 'arg2'); 
     }); 
</script> 

此代碼位於在體內。包括(在頭) 腳本是:

<script type="text/javascript" src="js/jquery-1.4.1.js"></script> 
<script type="text/javascript" src="js/jquery.ba-jqmq.js"></script> 

我已經與TamperData FF插件和AJAX的職位,以script.php的只是沒有發射檢查,我不知道爲什麼..

回答

0

在它說jqmq documents回調方法接受一個參數。你正試圖發送更多。 add方法的第二個參數是優先級,只能是布爾值。

queueObj.add(item [, priority ]); 

您應該將您的參數添加爲數組或對象。我創建了Fiddle,它似乎工作正常。

UPDATE: 另外,我認爲同時Ajax請求被限制爲3或4,所以你將不能夠有10

+0

感謝批!我錯過了從文檔..明天嘗試它作爲其上午4.20時間:)但看起來很有希望解決我的問題 – stevesrs 2012-07-10 09:21:20

+0

好,所以你的答案當然是正確的,但它不是唯一的問題。我記得我之所以非常不喜歡JS .. 該代碼缺少一堆結束標籤,如})和;在幾個地方和JS當然並沒有真正告訴你這個;嘿有沒有像PHP一樣在xx行上缺少一些東西:S – stevesrs 2012-07-10 21:11:34

+0

大多數IDE會在語法錯誤上發出警告,並且在瀏覽器控制檯中會顯示錯誤消息,如缺少的左括號。 ';'在javascript中是可選的。 – 2012-07-11 06:44:52