Pedro Chagas
asked on
Jquery and Ajax - go getting all the information
Hi E's, I have a script that made a call in Ajax (jQuery) for get data/information from a php file, like this:
My objective is create a progress bar, and in php file, I write some php "echo" like: echo "5"; in the beginning of the code, echo "50"; in the middle of the code, and so on, to reach 100.
Is possible change my code for every time php file show a "echo" execute this part of the code:
$("#optimizar_responsivo").click(function(){
$.ajax({
type: "GET",
url: "optimizar_responsivo.php?id=<? echo $_GET['id']; ?>",
success: function(dat){
if(dat == "sete"){
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&erro=Contacte o Suporte Tecnico do Painel de Controlo";
window.location=actual;
} else if(dat == "sucesso"){
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&restaurar=1";
window.location=actual;
}else{
alert(dat);
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&erro=Não foi possivel fazer uma optimização da imagem - É aconselhavel remover esta imagem do sistema";
window.location=actual;
}
}
});
});
The code above is correct, the problem is, they just be executed once!My objective is create a progress bar, and in php file, I write some php "echo" like: echo "5"; in the beginning of the code, echo "50"; in the middle of the code, and so on, to reach 100.
Is possible change my code for every time php file show a "echo" execute this part of the code:
if(dat == "sete"){
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&erro=Contacte o Suporte Tecnico do Painel de Controlo";
window.location=actual;
} else if(dat == "sucesso"){
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&restaurar=1";
window.location=actual;
}else{
alert(dat);
var actual = "imagem_edita.php?id=<? echo $_GET['id']; ?>&erro=Não foi possivel fazer uma optimização da imagem - É aconselhavel remover esta imagem do sistema";
window.location=actual;
}
The best regards, JC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With ajax there is no two way communication, the request is sent and then a listener waits for the response and closes the connection
Look at websockets (above) if you want real time communication with a server
Look at websockets (above) if you want real time communication with a server
ASKER
Ok thanks. To finalize, I not will use websockets, I thing I have a great idea and would like to know your opinion about it:
Because the php file, in average takes 10 seconds to process, I thing, in php file change "echo" for database update, and in my html file run a javascript script that verify each 1 second if have changes in data base.
It is a good idea?
~JC
Because the php file, in average takes 10 seconds to process, I thing, in php file change "echo" for database update, and in my html file run a javascript script that verify each 1 second if have changes in data base.
It is a good idea?
~JC
If I am understanding you correctly that might work.
ASKER
~JC