I am very new to PHP, but now I have to help my friend solve the problem with PHP.
He bought a PHP-based website, after he uploaded it to the host, he discovered that there was an error:
Fatal error: Call to undefined function json_encode() in xxx.php
The code is very simple:
echo json_encode(array( 'result' => true, ));
It sends json to the client.
I know that json_encode added after php 5.2, but the PHP version of its host is PHP 5.1.2, so the reason it reports an error.
But we do not have the right to update the PHP version of the host, so I need to change the code. How to allow json return to client without json_encode ?
The web page in the client browser will run this javascript code to get and verify that json is:
jQuery.ajax({ 'url': '...', ..., 'success':function(json) { if(json != null && json.result == true) {
Thanks a lot!
UPDATE
Since I do not have the right to update anything or install new libraries on this host, the only thing I can do is change the code. But I know almost nothing about php, that I do not know how to use third-party libraries. Finally, I fix this as:
In php:
echo '{"result":"true"}';
In javascript:
if(json!=null && json.result=="true") { // do something }
source share