首页  >  文章  >  后端开发  >  選取刪除與ajax?

選取刪除與ajax?

WBOY
WBOY原创
2016-09-12 17:44:441155浏览

先附上我的程式碼

<code><button class="box" data-removetype="select_del">刪除</button>
<form id="selectid">
 while ($row = mysql_fetch_array($s))
{
       <input type="checkbox" name="id[]" value="<? echo $row['mail_id'];?>">
 }
 ?>
 </form>
 
 $(".box").click(function(e){
    var removetype = e.currentTarget.dataset.removetype;
    /*mailbox*/
    if (removetype=='select_del')
    {
        $.ajax({
                type: "POST",
                url:"del?to="+removetype,
                data:$("#selectid").serialize(),
                cache: false,
                success: function(){
                
                }
            });
    }
});
</code>

del

<code>$user = $_GET['to'];
if ($user=='select_del')
{
    $getid=$_POST['id'];
    foreach($getid as $value)
    {
        $DEL = mysql_query("
        DELETE FROM `資料表名稱`
        WHERE `id` = '".$value."'
        ");
     }
}
</code>

以上是我的程式碼...
但卻無法運作
所以我想問看看這樣做法是不是對的?
確定id與資料表名稱無誤

回复内容:

先附上我的程式碼

<code><button class="box" data-removetype="select_del">刪除</button>
<form id="selectid">
 while ($row = mysql_fetch_array($s))
{
       <input type="checkbox" name="id[]" value="<? echo $row['mail_id'];?>">
 }
 ?>
 </form>
 
 $(".box").click(function(e){
    var removetype = e.currentTarget.dataset.removetype;
    /*mailbox*/
    if (removetype=='select_del')
    {
        $.ajax({
                type: "POST",
                url:"del?to="+removetype,
                data:$("#selectid").serialize(),
                cache: false,
                success: function(){
                
                }
            });
    }
});
</code>

del

<code>$user = $_GET['to'];
if ($user=='select_del')
{
    $getid=$_POST['id'];
    foreach($getid as $value)
    {
        $DEL = mysql_query("
        DELETE FROM `資料表名稱`
        WHERE `id` = '".$value."'
        ");
     }
}
</code>

以上是我的程式碼...
但卻無法運作
所以我想問看看這樣做法是不是對的?
確定id與資料表名稱無誤

<code>data:$("#selectid").serialize()</code>

你可以尝试替换为

<code>data:$("#selectid").find('input').serialize()</code>

如果不行的话,我觉得你需要检查一下脚本的写法,是否符合规范.如:
<a class=" <?php if($status==1): ?>selected<?php endif; ?>">RETURN</a>

你这么写

<code> while ($row = mysql_fetch_array($s))
{
       <input type="checkbox" name="id[]" value="<? echo $row['mail_id'];?>">
 }
 ?></code>

我不认为它能够正常工作....

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn