2016-09-17 115 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; 
}