2016-09-17 114 views
0

我需要添加JS警报以删除mysql中的某些记录。简单...确定要删除?是 - 导致页面删除,否 - 不执行任何操作。问题是每当我点击是它会打开一个新的标签,我不需要(希望在当前标签中的所有标签)。任何解决方案删除mysql数据的Javascript警报在新标签中打开

JS:

function confirmDelete(url) { 
var aa = event.srcElement.id; 
if (confirm("Sure to delete: "+ aa +"?")) { 
    window.open('/www/site/m_delete.php?id=' + aa +''); 
} else { 
    return false; 
}  

}

HTML:

<a class="box_setting fa fa-ban" style="cursor:pointer;" id="'.$id.'" onClick="confirmDelete(\'/www/site/m_delete.php?id='.$id.'\')"></a> 
+0

试window.location.pathname( '?/ m_delete.php ID =' + AA + ''); – Hadi290

回答

1

取代你的代码对于同一选项卡使用打开页面的代码: -

window.open('/www/site/m_delete.php?id=' + aa +'', '_self'); // _self refers to window/tab that the code is currently running 
0

您可以使用简单的XMLHttpRequest您删除页 - 这将是在后台打开此链接

function confirmDelete(url) { 
    var aa = event.srcElement.id; 
    if (confirm("Sure to delete: "+ aa +"?")) { 
     var xhttp = new XMLHttpRequest(); 
     xhttp.open("GET", '/www/site/m_delete.php?id='+aa, true); 
     xhttp.send(); 
} else { 
    return false; 
} 

Docs:http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

0

试试这个

window.location('/www/site/m_delete.php?id=' + aa +''); 

与此行只

0

如果m_delete.php只要有php代码,你可以很容易地在这个文件中包含这个文件,并且在$ _GET check中添加它。

像在当前页的beggining:

<?php 
    if(isset($_GET['id'])) 
    { 
      include '/www/site/m_delete.php'; 
    } 
?> 
<!-- page content --> 

function confirmDelete(url) { 
var aa = event.srcElement.id; 
if (confirm("Sure to delete: "+ aa +"?")) { 
    window.location.href = '?id=' + aa; 
} else { 
    return false; 
}