window.location.assign不会继续

时间:2018-02-06 09:38:06

标签: javascript php

我正在尝试删除数据库中的记录。

HTML

<a href="" onclick="return delUnit('grams');">DELETE</a>

JS

function delUnit(unit)
    {
    var r=window.confirm("Are you sure you want to delete this unit?");
    if (r==true)
      {
        //window.alert(val); I used alert to see if val was containing the word grams
        window.location.assign("deleteunit.php?val="+unit);
        return false;
      }
    }

PHP

$val = $_GET['val'];
mysql_query("DELETE FROM setuptb WHERE val='$val' AND category='UNIT'");

1 个答案:

答案 0 :(得分:2)

在window.location.assign()之后请添加return false; 像这样

window.location.assign("deleteunit.php?val="+unit);
return false;