我有一個從同一頁上的數據庫輸出的幾種形式。當我不使用ajax時它工作正常。當我使用Jquery時,它僅適用於第一種形式。任何人都可以向我指出正確的方向嗎?jquery和頁面上的多個表單
jQuery的.....
$('.updateSubmit').live('click', function() {
var id = $('.id').val();
var hardSoft = $('.hardSoft').val();
var brand = $('.brand').val();
var subCat = $('.subCat').val();
var subSubCat = $('.subSubCat').val();
var tProduct = $('.tProduct').val();
var description = $('.description').val();
var quantity = $('.quantity').val();
var price = $('.price').val();
var tCondition = $('.tCondition').val();
var featured = $('.featured').val();
var theData = 'id=' + id + '&hardSoft=' + hardSoft + '&brand=' +
brand + '&subCat=' + subCat +
'&subSubCat=' + subSubCat + '&tProduct=' + tProduct
+'&description=' + description +
'&quantity=' + quantity + '&price=' + price + '&tCondition=' +
tCondition + '&featured=' + featured;
$.ajax ({
type: 'POST',
url: '/updateGrab.php',
data: theData,
success: function(aaa) {
$('.'+id).append('<div class="forSuccess">'+aaa+'</div>');
} // end success
}); // end ajax
return false;
}); // end click
和我的PHP形式......
while ($row = $stmt->fetch()) {
echo " <form action='http://www.wbrock.com/updateGrab.php'
method='post' name='".$id."'>
<input type='hidden' class='id' name='id' value='".$id."' />
Hardware/Software
<input type='text' class='hardSoft' name='hardSoft'
value='".$hardSoft."' />
Brand
<input type='text' class='brand' name='brand' value='".$brand."' />
Sub-category
<input type='text' class='subCat' name='subCat'
value='".$subCat."' />
Sub-Sub-Cat
<input type='text' class='subSubCat' name='subSubCat'
value='".$subSubCat."' />
Product
<input type='text' class='tProduct' name='tProduct'
value='".$tProduct."' />
Description
<input type='text' class='description' name='description'
value='".$description."' />
Qty
<input type='text' class='quantity' name='quantity'
value='".$quantity."' />
Price
<input type='text' class='price' name='price' value='".$price."' />
Cond
<input type='text' class='tCondition'
name='tCondition'value='".$tCondition."' />
Featured
<input type='text' class='featured' name='featured'
value='".$featured."' />
<input type='submit' id='".$id."' class='updateSubmit'
name='updateSubmit' value='Update' />
</form>
<span class='".$id."'></span>
"; // end echo
} // end while loop from database
你可能想看看「連載()」 jQuery的方法 - 它聚集了表單字段和構建參數字符串爲您的工作:HTTP ://api.jquery.com/serialize/ – Pointy 2010-06-08 12:17:01