You can use AJAX, everything should be done by another page and the one where the user is will only send the commands (make the requests)
Code Example
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.php action should be ready to execute the actions when accessed let’s assume that the makeRequest() function was called as follows : makeRequest('inactive'), php will have to look like this one:
switch ($_GET['action']){
case 'inativo':
//o que o php deverá fazer
;
}
Knob
1° Import the Jquery library <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
place before closing the tag body
.
2° Function alertContents() Soon 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>');
}
}
Inside a script tag
- Knob:
In php put the button code inside div with the id 'button' before the Jquery library import is:
Inactive <button id="inativo">Deixar Inativo</button>
For Active <button id="ativo">Deixar Ativo</button>
- Click the button
In the script tag in which the alertContents() function was declared before closing the tag paste the following code:
$("#ativo").click(function(){
makeRequest('ativo');
});
$("#inativo").click(function(){
makeRequest('inativo');
});
Use a
mysqli_query
withUPDATE table SET status=status WHERE id in ('id_do_aluno')
– Pedro Pinto
That’s right, buddy, but no refresh ? take a look at me if, the whole part of php is quiet, the problem is changing the name from active to disabled with javascript or some other way.
– Jaimir Tapia
and if it were a
.php
external?– Pedro Pinto
Yes, I thought I could without a javascript that calls an external php with POST and then query new status and go back to page and update only the active word.
– Jaimir Tapia
The problem is that I don’t know how to do this with javascript.
– Jaimir Tapia