Various javascript errors in OJS 3.1.1-2

Hi,
We are experiencing some JS errors in OJS 3.1.1-2. Seems like they are browser-dependent. None of them are related to any network errors, i.e. only status 200 for all requests. The JS build should be up to date, and browser-caching has been turned off.

  • In the metadata modal for submissions when you click save in Chrome, we get the following error (and an eternal spinner).

      Uncaught SyntaxError: Unexpected token o in JSON at position 1
          at JSON.parse (<anonymous>)
          at Function.n.parseJSON (jquery.min.js:formatted:3706)
          at Object.success (pkp.min.js:formatted:4601)
          at j (jquery.min.js:formatted:1341)
         ...
    

    Using the Chrome debugger I found out that the problem is that JSON.parse() is sent an object, not a string, in the jQuery method.

  • In Chrome on Windows (Version 69.0.3497.92 (Official Build) (64-bit)), but not on Mac (exactly the same version), clicking “more information” on a submission file opens the modal but the spinner never stops, and no information is shown, we get the same error message in the console as above. [Edit: Solution: turn off uBlock]

  • In Firefox, sometimes, unpredictably, an unknown API error flashes by and disappears. The JS log shows the following:

      TypeError: b is undefined
      pkp.min.js:315:449
      a.pkp.controllers.modal.ModalHandler.prototype.modalOpen
      https://.../js/pkp.min.js:315:449
      ajaxErrorCallback
      https://.../js/build.js:6:36667
      n
      ...

did you try clearing your browser cache? (sorry, you already mentioned that…)

Yes, all caches cleared and disabled.

So, not sure if it helps, but found out now that the first error only occurs in the “Metadata” modal for articles in production, not for “Show metadata” for submissions that have not gone to production yet.

Are there any related PHP errors?

There are no errors, but the following warning is printed 4 times after I click save:

PHP Warning:  Cannot use a scalar value as an array in ..../lib/pkp/classes/core/DataObject.inc.php on line 133

Not sure if it’s related.

Actually, are there any problems with tables in the database in fields related to localized submission metadata? For example, wrong encoding, unusual values? And what about PHP version and extensions? But in this case, the problem would not be browser related…

I added the following debug code to line 133

error_log('DEBUG: key = ' . $key . ', locale = ' . $locale . ', value = ' . $value . '\n');

And it seems every time the above warning is printed, I get following right before:

DEBUG: key = metaCitations, locale = nb_NO, value = 1\\n referer: https://..../index.php/test/management/settings/access

For this particular journal, nb_NO, is only activated for UI, english is the primary locale.

That comes from journal_settings table, there you can find pairs settings_name → settings_value. There can be found setting metaCitations for each journal. I personally don’t know where it is used in OJS3. But I’ve found a similar thread with exact PHP warning. In particular, the solution from Alec: Cannot use a scalar as an array - #21 by asmecher

Thanks! That got rid of the warning in the log, and the frontend error changed character. Now I don’t get the eternal spinner, instead I get the following two errors in the form (at the top of the modal):

Errors occurred processing this form
[Please enter the title of your article. (Norsk BokmĂĄl)]
[Please enter your article’s abstract. (Norsk Bokmål)]

Even though the fields are filled out in the form. Now nothing is printed to the server log. Norsk Bokmål (nb_NO) is only activated for the UI for this journal, and I’m editing using en_US, which is the primarty locale.

are the forms enabled for Norvegian from Settings > Website > Languages? edit: I see they are not. I have encountered similar situations when using only Finnish locale.

Even if I deactivate no_NB completely for that journal, I still get the same error.

In the journal_settings table I would check also: supportedSubmissionLocales, supportedLocales and supportedFormLocales. The values there have a form of arrays. nb_NO locale should appear only in a second setting. Also can be helpful looking at the submission_setting table, particularly at the submission(s) you encountered the problem with. They can be found by submission_id. Particularly, settings: title and abstract; they are localized.

This OJS instance is the one upgraded from OJS 2+, right? I’m not an expert in this field. Never have seen such error before. Were there any problems with an upgrade process before?

This is what I get:

ojs => select * from journal_settings where journal_id = 30 and setting_name like '%supported%';

 journal_id | locale |        setting_name        |                                     setting_value                                      | setting_type
------------+--------+----------------------------+----------------------------------------------------------------------------------------+--------------
         30 |        | supportedSubmissionLocales | a:1:{i:0;s:5:"en_US";}                                                                 | object
         30 |        | supportedFormLocales       | a:1:{i:0;s:5:"en_US";}                                                                 | object
         30 |        | supportedLocales           | a:5:{i:0;s:5:"en_US";i:1;s:5:"nb_NO";i:2;s:5:"es_ES";i:3;s:5:"fr_CA";i:4;s:5:"it_IT";} | object

Looks correct, right?

I think the problem I have experienced occurs when you have a submission made with for example fi_FI locale (the submission locale is fi_FI) but forms for that locale are not enabled.

Interesting, that solved the form problem (edit: by activating nb_NO for forms), but now we’re back to the eternal spinner and the JSON.parse() error described originally. Still no errors in the log.

Tagging here @asmecher and @NateWr

This is usually far fetched, but check that the browsers you are testing this with do not have any advertisement filtering plugins enabled. Like uBlock.

No adblockers, as far as I can tell. And most of the JS seems to work most of the time, it’s just a few widgets that are affected.

Ok, just sounded a bit like this: OJS3: Reviewer files > More Information > History does not load