2
I have following code:
<script>
$.post('http://localhost/app/user.php', {acao: acao}, function(retorna){
$("#demo").html(retorna);
if(retorna == "sucesso") {faça x}
});
</script>
But in the user.php
he returns several echo
dentros of conditions if
. So if I have in PHP, for example, echo "sucesso";
and another echo "sucesso";
he returns success.
I would like to know how I do to catch each of that return separately?
João, I did what you did and it returned in JSON format: {"status":"Success","line":1} but I’m not getting the condition in javascript with the return status..
– rhundler
@rhundler tries like this > var data = jQuery.parseJSON(returns); then data.
– LucaoA
@rhundler lacked a configuration in his javascript now that I saw, I’ve done the editing! look there need not convert anything saw! At the end of the
function(retorna){}, 'json');
so that he understands that the return is a json– user46523
@rhundler
The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).
missing to specify the return! link: https://api.jquery.com/jquery.post/. I edited in my reply– user46523
Excellent! It worked perfectly after adding json. Thank you!
– rhundler