You can use AJAX, everything should be done by another page and the one where the user is only going to send the commands (make the requisitions)
Code Sample
var httpRequest = new XMLHttpRequest();
function makeRequest(acao) { //chame a função dizendo qual será a ação
httpRequest.open('GET', 'action.php?action='+acao); //Diga o método e a URL
httpRequest.send();
httpRequest.onreadystatechange=function(){ //Quando o retorno estiver pronto
if (httpRequest.readyState === 4) {//Processo concluído
alertContents(); //Função que dirá que a função foi completada
}
}
}
Action.php
The action.php should be ready to perform the actions when it is accessed let's assume that the makeRequest () function was called as follows: makeRequest ('inactive'), php will have it with a code similar to this:
switch ($_GET['action']){
case 'inativo':
//o que o php deverá fazer
;
}
Button
1st Import the JQuery library <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
place before the closing of the body
tag.
2nd function alertContents () Immediately after importing the JQuery library use the following code:
function alertContents(){
if($('#button').html() == '<button id="ativo">Deixar Ativo</button>'){
$('#button').html('<button id="inativo">Deixar Inativo</button>')
}
else{
$('#button').html('<button id="ativo">Deixar Ativo</button>');
}
}
Within a tag script
Button:
In php put the button code inside div with the 'button' id before the import of the JQuery library being:
Inactive <button id="inativo">Deixar Inativo</button>
For Active <button id="ativo">Deixar Ativo</button>
Click the
In the script tag where the alertContents () function was declared before tag closing, paste the following code:
$("#ativo").click(function(){
makeRequest('ativo');
});
$("#inativo").click(function(){
makeRequest('inativo');
});