-3

我试图将 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;
4

1 回答 1

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>
于 2013-07-07T14:51:25.703 回答