2011-06-10 103 views
0

如果你看看http://www.danfarrellwright.com/screwsline/front_end/product.php?product_id=104 我寫了下面的函數添加表頭中每五行:JQuery的AJAX問題

jQuery.fn.hrReplace = function() { 
    var headers = $(this).find('table.products tr:eq(0)'); 

    $(this).find('table.products tr:nth-child(5n)').after(headers); 
    $(this).find('table.products tr:eq(0)').before(headers); 
} 

這個工程上加載頁面的罰款。然後我在ajax命令中添加了這個功能:

$.ajax({ 
    type: "POST", 
    url: formAction, 
    data: myForm, 
    success: function() { 
     $('#top_bar').load(base + 'index.php #top_bar'); 
     $('#' + divId).load(document.URL + '&random=' + Math.random() * 99999 + ' #' + divId, { 
      'gaugeMinFil':parseFloat($('input[name="gaugeLow"]').val()), 
      'gaugeMaxFil':parseFloat($('input[name="gaugeHigh"]').val()), 
      'lengthMinFil':parseFloat($('input[name="lengthLow"]').val()), 
      'lengthMaxFil':parseFloat($('input[name="lengthHigh"]').val()) 
     }); 
     $('#tableHolder').hrReplace(); 
    } 
}); 

但是在重新加載div後,hrReplace()不起作用。

+0

什麼問題?另外,請在「不工作」的位置提供更多詳細信息 – 2011-06-10 18:37:44

+0

對不起,hrReplace函數從表中取出標題行並將其插入表中的第五行。在完成表格的AJAX重新加載之後,函數不再在每五行中插入標題行。 – 2011-06-10 18:39:50

+0

'headers'參數來自哪裏? – Tgr 2011-06-10 18:42:38

回答

1

函數調用需要位於.load調用的回調中,因此它在完成後發生。

$.ajax({ 
    type: "POST", 
    url: formAction, 
    data: myForm, 
    success: function() { 
     $('#top_bar').load(base + 'index.php #top_bar'); 
     $('#' + divId).load(document.URL + '&random=' + Math.random() * 99999 + ' #' + divId, 
      { 
      'gaugeMinFil':parseFloat($('input[name="gaugeLow"]').val()), 
      'gaugeMaxFil':parseFloat($('input[name="gaugeHigh"]').val()), 
      'lengthMinFil':parseFloat($('input[name="lengthLow"]').val()), 
      'lengthMaxFil':parseFloat($('input[name="lengthHigh"]').val()) 
      }, 
      function() { 
       $('#tableHolder').hrReplace(); 
      } 
     ); 
    } 
}); 
+0

Awesome Fosco,works!「 – 2011-06-10 18:43:16

+0

@bland_dan太棒了..很高興我能幫上忙。 – Fosco 2011-06-10 18:44:14