2010-11-12 202 views
0
$('.removeItem').live('click',function(){          
         var postData = {}; 
         $(this).closest('tr').find('.tableRow'){ 
          var keyPrefix = 'data[' + index + ']'; 
          postData[keyPrefix + '[index]'] = $(this).closest('tr').find('.row_id').text(); 
          postData['data['+ index +'][order_id]'] = $('#order_id').text(); 
         }; 

我不確定它是否顯而易見我正在嘗試做什麼,我錯了?

編輯:

完全是我的錯,稍微在原來的職位誤導,這是我的完整代碼:

$('.removeItem').live('click',function(){          
        var postData = {}; 
        $(this).closest('tr').find('.tableRow'){ 
         var keyPrefix = 'data[' + index + ']'; 
         postData[keyPrefix + '[index]'] = $(this).closest('tr').find('.row_id').text(); 
         postData['data['+ index +'][order_id]'] = $('#order_id').text(); 
        )}; 

       $.ajax 
        ({ 
        type: "POST", 
        url: "deleterow.php", 
        dataType: "json", 
        data: postData, 
        cache: false, 
        success: function() 
         { 
          alert("Item Deleted"); 
         } 
        });   
       $(this).closest('tr').remove(); 
       calcTotal(); 
      }); 
+0

一旦你走到這一步:'$(本).closest( 'TR')找到(」 tablerow的。 ')'你想完成什麼?你是否想在這個包裝集上運行後續代碼塊? – 2010-11-12 13:30:08

回答

1

的 「指數」 變量來看,我認爲代碼應該是:

$('.removeItem').live('click', function() { 
    var postData = {}; 
    $(this).closest('tr').find('.tableRow').each(function(index) { 
    var keyPrefix = 'data[' + index + ']'; 
    postData[keyPrefix + '[index]'] = $(this).closest('tr').find('.row_id').text(); 
    postData['data[' + index + '][order_id]'] = $('#order_id').text(); 
    }); 
}); 
2

你忘了在.live呼叫收盤)

忽視回調的內容,你的代碼是

$('.removeItem').live('click',function(){ ... } ; 
              ^

注意你調用一個函數有兩個參數,但不關閉括號。

+0

是的,這也是一個問題。 – Pointy 2010-11-12 13:27:32

+0

對不起,修改我的OP,這應該使我的意圖更清晰! – benhowdle89 2010-11-12 13:34:17

3

此行這裏:

   $(this).closest('tr').find('.tableRow'){ 

缺少的東西。什麼?不清楚,但也許它應該是

   $(this).closest('tr').find('.tableRow').each(function() { 
+0

打我吧。我也懷疑每個()。 – 2010-11-12 13:29:01

1

您不關閉「活」功能塊。您需要將});添加到最後一行的末尾。