我试图将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;
答案 0 :(得分:1)
尝试使用以下代码段:
<script>
function _Submit(form){
$('#cancel-server'+form.id).ajaxForm({ }););
return false;
}
</script>
<form id="cancel-server<?php echo $row['id']; ?>" action="process.php" method="POST" onsubmit="javascript: return _Submit(this);">
...
</form>