0
The result is coming with quotes and do not know how to remove.
In PHP:
if ($finalImage) {
echo json_encode(sucesso);
exit;
}
if (!$finalImage) {
echo json_encode('erro');
exit;
}
In ajax:
success: function(result) {
console.log(result);
if(result == "sucesso") {
mopageFix();
$('.mopageFix').load('data/photo/amostraCrop.php');
if(result == "erro") {
mopage();
$('.mopage').load('data/admdata.php?crop=no');
}
The console.log(result) is resulting: "success"
Question: How to remove quotes from json_encode(sucesso)
Or how to quote (result == "sucesso")
?
Thank you!
Because it doesn’t just put
echo "sucesso";
andecho "erro";
?– Sam
If you put
echo "sucesso";
will return onlysucesso
without quotation marks, and JS compares how it is already doing:result == "sucesso"
– Sam
You may need to use . Trim() in the result:
if(result.trim() == "sucesso")
... because if the stringsucesso
come with some space before or after (or both), theif
will not validate.– Sam
That’s right Sam... Tim worked! I posted the image of the console.log, take a "look over" see that there is a lot of space... and my lack of experience didn’t even make me notice... and look that "I fucked" enough... kkkk... wobble... Thank you my "friend"!
– user34782
What to use
json_encode()
in this case, if you’re not even passing array, and why you don’t justecho "sucesso";
??? Actually you didn’t intend to pass a variable like this?json_encode($sucesso);
?– Ivan Ferrer
json_encode is to return in json format: example
json_encode(['a' => 'b']);
will resume:{"a": "b"}
and in javascript, vc captures through an anonymous function, for example the return: date. a, will print "b". in case yourresult
.– Ivan Ferrer
Poxa Ivan, thank you for your kindness! I was able to solve with Trim and I already removed json_encode(). Too good to learn... again thank you and may God enlighten you!
– user34782