J'ai plusieurs formulaires qui sont sortis d'une base de données sur la même page. Cela fonctionne bien quand je n'utilise pas ajax. Quand j'utilise Jquery, cela ne fonctionne que pour le premier formulaire. Quelqu'un pourrait-il me diriger dans la bonne direction s'il vous plaît?Jquery et plusieurs formulaires sur une page
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
et ma forme 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
Vous pouvez regarder le « serialize() » méthode jQuery - il fait le travail de collecte des champs de formulaire et la construction de la chaîne de paramètres pour vous: http : //api.jquery.com/serialize/ – Pointy