PHP Deprecated (Failed Ajax request or invalid JSON returned.) (OJS-3.4.0.5)

Good day @everyone

I encountered an error message when I accessed the “Issues” section of the admin page.
“Failed Ajax request or invalid JSON returned”

After purchasing Website Security, I began receiving an error warning when attempting to update articles in the current volume’s issues. Previously, without Website Security enabled, the error notice I got was connected to the ORCID plugin, which I ignored because it did not interfere with my ability to upload articles and full papers. Now, the new version of OJS displays a different error message(Failed Ajax request or invalid JSON returned), which appears to be the first I encountered after enabling security.

PHP Error Log:
1st:
[21-May-2024 14:05:57 UTC] PHP Deprecated: mb_convert_encoding(): Passing null to parameter #1 ($string) of type array|string is deprecated in /home/root/public_html/lib/pkp/classes/search/SubmissionSearchIndex.php on line 51

        // Attempts to fix bad UTF-8 characters
        $previous = mb_substitute_character();
        mb_substitute_character('none');
        $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8'); //line 51 PHP Deprecated: mb_convert_encoding(): Passing null to parameter #1 ($string) of type array|string is deprecated
        mb_substitute_character($previous);

I read this post Charrecter Encoding Problem - Convert data from 2.3.5 to 3.1 and it give me and idea to check in my database format.

PhpMyAdmin Database:

All Type of Tables =“InnoDB”
and some Collation of the tables = “latin1_swedish_ci”, and “utf8mb3_general_ci”;

2nd

[21-May-2024 14:05:57 UTC] Exception: The ORCID plugin is enabled, but its settings are invalid. In order to fix, access the plugin settings and try to save the form in /home/root/public_html/plugins/generic/orcidProfile/OrcidProfilePlugin.php:106
Stack trace:
#0 /home/root/public_html/lib/pkp/classes/plugins/PluginRegistry.php(76): APP\plugins\generic\orcidProfile\OrcidProfilePlugin->register('generic', 'plugins/generic...', NULL)
#1 /home/root/public_html/lib/pkp/classes/plugins/PluginRegistry.php(121): PKP\plugins\PluginRegistry::register('generic', Object(APP\plugins\generic\orcidProfile\OrcidProfilePlugin), 'plugins/generic...', NULL)
#2 [internal function]: PKP\plugins\PluginRegistry::PKP\plugins\{closure}(Object(APP\plugins\generic\orcidProfile\OrcidProfilePlugin), 'plugins/generic...')
#3 /home/root/public_html/lib/pkp/classes/plugins/PluginRegistry.php(121): array_walk_recursive(Array, Object(Closure))
#4 /home/root/public_html/lib/pkp/classes/core/Dispatcher.php(155): PKP\plugins\PluginRegistry::loadCategory('generic', true)
#5 /home/root/public_html/lib/pkp/classes/core/PKPApplication.php(388): PKP\core\Dispatcher->dispatch(Object(APP\core\Request))
#6 /home/root/public_html/index.php(21): PKP\core\PKPApplication->execute()
#7 {main}
[21-May-2024 14:05:57 UTC] Exception: The ORCID plugin is enabled, but its settings are invalid. In order to fix, access the plugin settings and try to save the form in /home/root/public_html/plugins/generic/orcidProfile/OrcidProfilePlugin.php:106

Please help,

Best Regards,
Darryl Nuyda

Hi everyone,

I’m reaching out for assistance with an error I’m encountering. I’ve searched through previous posts related to the issue, but unfortunately, haven’t found a solution yet.

Best Regards

The error messages look dramatic, but should not cause an issue.

These JSON issues often stem from debug statements in the response.
In your config.inc.php - did you enable any debug option? If so try disabling them and try again.

Hi @cager ;

These JSON issues often stem from debug statements in the response.
In your config.inc.php - did you enable any debug option? If so try disabling them and try again.

I checked the config.inc.ph file, but there are no debug settings turned on.

image

I suspected the ORCID and TextAreas plugins might be causing the error, so I deleted them. However, the error persists throughout the entire Open Journal System (OJS) platform.

Like this:

When I try to export a DOI, I receive an error message.

Php Error log:

[23-May-2024 14:22:06 UTC] PHP Deprecated:  stripslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/philair/public_html/lib/pkp/classes/citation/Citation.php on line 118

Trying to on the Debug: Here is the error pop up

is the error:
mb_convert_encoding()

I followed this and apply it: Resolving charset encoding mix-ups / mojibake - #9 by jnugent

All Collation was changed to utf8mb4_general_ci:

but the error is sam mb_convert_encoding();

I’m hoping you can help! I’m having trouble uploading the full article to the content publishing platform. The functionality seems a bit confusing, and it’s slowing down my progress.

Best Regards,

Darryl

what you see are just notices to developers, not errors. Seeing messages like these is perfectly normal when debug is turned on and doesn’t indicate an error.

It also means my hunch was wrong. So not sure if I can help. Maybe it’s an issue outside ojs. have you checked the network inspector in the browser?

@cager ;

Thanks for the response;

Here is the result in the DevTool:
Console:

Network:

Maybe it’s an issue outside ojs. have you checked the network inspector in the browser?

There seems to be a problem. After enabling website security on the website, an error message started appearing.

Best Regards,

@OJS_Darryl

What is probably happening here is that PHP is generating this code notice, which is being sent back to the browser instead of just to the error log, and this is breaking the returned JSON. JSON has a very specific format and if PHP is printing out an error message to the browser, this act will break the JSON.

You are probably missing this commit in your code:

Which specifically tests to see if $text is null and returns instead, to prevent the call to mb_convert_encoding() with a null value.

Easiest thing to do is to apply that small patch to your file.

Best,
Jason

1 Like

@jnugent ;

You’re a lifesaver!

classes/search/SubmissionSearchIndex.php

I applied the code to both lib/pkp/classes/search/SubmissionSearchIndex.php and classes/search/SubmissionSearchIndex.php . it WORK for me.

$text = join("\n", $text);
        }
//add this patch
        if (!strlen($text ?? '')) {
            return [];
        }
//end patch
        // Attempts to fix bad UTF-8 characters
        $previous = mb_substitute_character();
        mb_substitute_character('none');

Best Regards
Darryl Nuyda

@jnugent ;

I’m encountering an issue again where I can’t generate a DOI for a newly published article.

I’m trying to export/deposit all [data/files/items], but I’m getting an error message.

Php Error Log:

[26-May-2024 05:25:21 UTC] PHP Deprecated:  Return type of Slim\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/root/public_html/lib/pkp/lib/vendor/slim/slim/Slim/Collection.php on line 112

I successfully exported a DOI in the past. However, when I try to generate/export a DOI for a new article I just published, I receive an error message. Is there anything specific I should check for new articles?

I am looking for this in the ojs folder to try this code Not find DOI Plugin? - #25 by mgax

Best regards;

Darryl

Hi @OJS_Darryl

Anything in the vendor directory is a third party library bundled with OJS, so we don’t maintain that code. If this used to work but now does not, did you recently upgrade PHP versions?

Best
Jason

Hello @jnugent

Anything in the vendor directory is a third party library bundled with OJS, so we don’t maintain that code. If this used to work but now does not, did you recently upgrade PHP versions?

Yes, PHP Version 8.2.

Best Regards

Darryl

Hi Darryl,

If the PHP version is a recent change, then maybe look at the notice and warning settings in your php.ini file (phpinfo will tell you which one is being used) and make sure the errors aren’t being sent as output to the browser, or disable deprecation warnings completely.

Best
Jason

Hello @jnugent

This is what you mean disabling the error_reporting?

Best Regards

I have also a same problem on this topic [All Generic plugins error including custom block manager (Failed ajax request or invalid JSON returned)](https://All Generic plugins error including custom block manager (Failed ajax request or invalid JSON returned))

Best Regards
Darryl

Hi Darryl,

There’s a directive in php.ini called

display_errors = Off

which will determine if the errors just get logged, or if they get sent to the browser. You want that turned Off for production since the display of the error will break the format of the returned JSON. I think this might be causing your issue.

Best
Jason

Hello @jnugent;

I log in to WHM and check the php.ini.

display_errors = Off

and the error still remain the citation

[05-Jun-2024 13:49:42 UTC] PHP Deprecated: stripslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/philair/public_html/lib/pkp/classes/citation/Citation.php on line 118

Best Regards,
Darryl