I handle some functions via PHP and in the end I return the AJAX client with useful information. Such information is contained in an array that is converted to JSON by json_encode()
. The problem is that I get sent an error message with the following:
SyntaxError: Unexpected end of input
This error happens because json_encode()
is not returning any array . I have my variable:
$data = array(
'command' => $command,
'message' => $message
);
And the result of var_dump
for json_encode()
is as follows (I put the HTML code for better visualization, execute it):
<pre class='xdebug-var-dump' dir='ltr'><small>boolean</small> <font color='#75507b'>false</font>
</pre>
The problem only happens when the value of the variable $message
is coming from an error in the database, if I write anything in it, the return is normal:
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'{"command":2,"message":"Qualquer coisa"}'</font> <i>(length=40)</i>
</pre>{"command":2,"message":"Qualquer coisa"}
Here is the var_dump
of an example of a return of the variable $message
:
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'Erreur de syntaxe pr�s de ''NomeDeUsuario', '$2a$05$Zx3hjrLOnWvNzZpRIhdcPecjreTjjaBkaYLrH7IRcfmn110et/92G',' � la ligne 1'</font> <i>(length=121)</i>
</pre>
Notice that this is an error in the database. The error itself is not relevant, I even caused it to test the return of errors to the client.