我试图将 ajax 形式放入 while 元素中,但不起作用。可能无法以ajax形式重复id。
<?php while(..){ ?>
<form id="cancel-server" action="process.php" method="POST">
<input type="hidden" name="task" value="cancel-server" />
<input type="hidden" name="serverid" value="<?php echo $row['sid']; ?>" />
<button type="submit" id="ah">
<i class="icon-remove"></i> Otkaži narudžbinu
</button>
</form>
<?php } ?>
jQuery:
$('#cancel-server').ajaxForm({
success: function(result){
var result=trim(result);
if(result=='success'){
$.poruka('', 'Success!');
}else{
$.poruka('', result);
}
}
});
php:
case 'cancel-server':
$serverid = $_POST['serverid'];
query_basic("DELETE FROM `serveri_naruceni` WHERE `id` = '".$serverid."'");
echo 'success';
break;