Unexpected end of JSON input after migrating/upgrading

Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -
Number of replies: 32

Hello.

I migrated our old Moodle site to a new server (CloudLinux 7.7, MariaDB 10.1 with Nginx -> Apache, PHP 7.3) a week ago and upgraded it (2.3.3) to the latest version ( > 2.7.20 > 3.2.9 > 3.8 > 3.8.1, all checks were green when upgrading) and everything seemed to be working just fine. 

However when I try to add a user to a course, I get the following errors in debug mode:

SyntaxError
Unexpected end of JSON input
Tiedosto:
Line:
Stack trace:
SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78358
    at l (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78475)
    at XMLHttpRequest.<anonymous> (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:81117)
SyntaxError
Unexpected end of JSON input
Tiedosto:
Line:
Stack trace:
SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78358
    at l (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78475)
    at XMLHttpRequest.<anonymous> (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:81117)
SyntaxError
Unexpected end of JSON input
Tiedosto:
Line:
Stack trace:
SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78358
    at l (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78475)
    at XMLHttpRequest.<anonymous> (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:81117)
SyntaxError
Unexpected end of JSON input
Tiedosto:
Line:
Stack trace:
SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78358
    at l (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78475)
    at XMLHttpRequest.<anonymous> (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:81117)

Any ideas how to fix this problem?

In reply to Kalle Isotalus

Re: Unexpected end of JSON input after migrating/upgrading

от Howard Miller -
Снимка на Core developers Снимка на Documentation writers Снимка на Particularly helpful Moodlers Снимка на Peer reviewers Снимка на Plugin developers
I would start by switching on Debugging (if you haven't) and checking your web server's error log. This might be the result of some other problem 'breaking' the javascript.
In reply to Howard Miller

Vs: Re: Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -
Thank you for the response.

I had enabled debugging in config.php to get the above error message
@error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!
@ini_set('display_errors', '1');         // NOT FOR PRODUCTION SERVERS!
$CFG->debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!
$CFG->debugdisplay = 1;              // NOT FOR PRODUCTION SERVERS!

Nothing has showed up in the error log regarding this problem on the server side.

In reply to Kalle Isotalus

Re: Vs: Re: Unexpected end of JSON input after migrating/upgrading

от Howard Miller -
Снимка на Core developers Снимка на Documentation writers Снимка на Particularly helpful Moodlers Снимка на Peer reviewers Снимка на Plugin developers
Assuming that you did this for a reason... what was the original problem that led you to discovering these messages?
In reply to Howard Miller

Vs: Re: Vs: Re: Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -
I received a message telling me that the end users can not add new users to a course. After that I checked the server logs and turned debugging on to see what was really happening. The moment I click the button to add a user to the course, that error shows up.
In short, this is the original problem.
In reply to Kalle Isotalus

Re: Vs: Re: Unexpected end of JSON input after migrating/upgrading

от Matteo Scaramuccia -

Hi Kalle,

Nothing has showed up in the error log regarding this problem on the server side.

please, open the Developer Tools of your browser (e.g. <F12>) and look at the HTTP Response of the request producing the broken JSON in the Network pane: it could be a plain HTML with a Moodle error explaining what was wrong.

HTH,
Matteo

In reply to Matteo Scaramuccia

Vs: Re: Vs: Re: Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -

Here's an image from the network tab, and the contents of the first header. I cleared the view before pressing the button that triggers the error.

HEADER:
General:
Request URL: https://mysite.tld/lib/ajax/service.php?sesskey=8QG9YOjb7c&info=core_get_fragment
Request Method: POST
Status Code: 200 
Remote Address: xx.xx.xx.xx:443
Referrer Policy: no-referrer-when-downgrade
Response Headers:
accept-ranges: none
cache-control: private, pre-check=0, post-check=0, max-age=0, no-transform
content-language: fi
content-length: 0
content-script-type: text/javascript
content-style-type: text/css
content-type: text/html; charset=utf-8
date: Wed, 12 Feb 2020 14:12:53 GMT
expires: 
pragma: no-cache
server: nginx/1.16.1
status: 200
x-frame-options: sameorigin
x-ua-compatible: IE=edge
Request Headers:
:authority: mysite.tld
:method: POST
:path: /lib/ajax/service.php?sesskey=8QG9YOjb7c&info=core_get_fragment
:scheme: https
accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: fi-FI,fi;q=0.9,en-US;q=0.8,en;q=0.7
content-length: 139
content-type: application/json
cookie: MoodleSession=cm1cgu1rtpuuu8t9jemqv7eclh
origin: https://mysite.tld
referer: https://mysite.tld/user/index.php?page=0&perpage=20&contextid=0&id=73&newcourse
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
x-requested-with: XMLHttpRequest
Query String Parameters:
sesskey: 8QG9YOjb7c
info: core_get_fragment
Request Payload:
[{index: 0, methodname: "core_get_fragment",…}]
0: {index: 0, methodname: "core_get_fragment",…}

This shows up multiple times in the console view:

jquery-3.4.1.min.js:2 jQuery.Deferred exception: Unexpected end of JSON input SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78358
    at l (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:78475)
    at XMLHttpRequest.<anonymous> (https://mysite.tld/lib/javascript.php/1580978682/lib/jquery/jquery-3.4.1.min.js:2:81117) undefined


Attachment moodle-error.png
In reply to Kalle Isotalus

Vs: Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -
Is there anything else I could do to troubleshoot this problem?
In reply to Kalle Isotalus

Re: Vs: Unexpected end of JSON input after migrating/upgrading

от Howard Miller -
Снимка на Core developers Снимка на Documentation writers Снимка на Particularly helpful Moodlers Снимка на Peer reviewers Снимка на Plugin developers
I'm really struggling with this one. You *could* turn off Javascript caching in config.php by adding...

$CFG->cachejs = false;

Clear your caches (Developer_tools) and try again. I'm hoping you might get a slightly more informative error.
In reply to Howard Miller

Vs: Re: Vs: Unexpected end of JSON input after migrating/upgrading

от Kalle Isotalus -
I did those, and I actually managed to open the enrollment page. I get the following warning in the console on that page:
warn: The moodle-core-notification parent module has been deprecated. Please use one of its subclasses instead.
https://mysite.tld/theme/yui_combo.php?rollup/3.17.2/yui-moodlesimple.js

The moment I remove $CFG->cachejs = false; from the config it breaks again, and I get the same errors as before.

What seems to be to key to success is clicking the enrol users -button before all the .js get loaded. It's obviously a lot harder to get there when cachejs is set as true.

I took screenshots how the pages get loaded, and what happens when I press the button. The parts after MathMenu.js?V=2.7.2 are the ones which get loaded after pressing the button and getting the error pop up.

Attachment cachejs_false.png
Attachment cachejs_true.png
In reply to Kalle Isotalus

Re: Unexpected end of JSON input after migrating/upgrading

от Mario Torres -

The headers of the request are not set to json. You must specify at lib/ajax/service.php the header after  json_encode. So the final script should end with:

  header('Content-Type:application/json');

  echo json_encode($responses);

In reply to Mario Torres

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
Hello, I' having the error

syntaxError
Unexpected end of JSON input

when I want to upload a file into moodle.

I read the forum and tried to fix the problem , but couldn't. I'm new at coding.

Could you please help me? I can't find the error

Josefina
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

Please tell us 1) which version of Moodle you're using, and 2) which additional plugins are installed on the site and which versions these plugins are (under Site administration ▸ Plugins ▸ Plugins overview and click Additional plugins to see these).

This reply includes some steps for finding which request is getting the unexpected JSON characters. In that reply it was caused by an additional plugin that wasn't compatible with the version of Moodle.

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
Thanks for your reply!!
the moodle version is 3.8.6

the additional plugins are:
mod_attendance: 3.9.1 2020120300
mod_customcert: 3.8.5 2019111805
mod_hvp: 1.21.0 2020080400
block_configurable_reports: 3.9.0 2020110300
block_mycertificates: Version for Moodle 3.4 onwards 2020061300
block_xp: 3.10.0 2020090300
qformat_h5p: 1.0.5 2020071507
filter_generico: Version 1.4.11(Build 2021010400) 2021010400
filter_h5p: 1.2 (Build: 2020061100) 2020061100
In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

Can you tell us when the "Unexpected end of JSON input" appears, for example, when an assignment is being uploaded? Or when a file resource is being uploaded? Or when a course image is being uploaded?

Maybe it happens for all of these but it would help if you could give examples of specific uploads that get this error.

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
Hello Leon,
The error appears when I'm uploading a recovery file to restore a course. what I don't understand is that the first 3 courses that I restored no error appeared but in the 4th this happened.

the files are in a repository folder.

I'm uploading some more captures that I took at the last try hopping this would help to clarify the problem
Attachment Captura de pantalla 2021-01-25 213910.jpg
Attachment Captura de pantalla 2021-01-25 213943.jpg
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

Have you tried this from another computer? Looking at the captures there are requests to Kaspersky Labs that respond with 503 Service Unavailable. So I'm wondering if there's some Kaspersky Labs software on your computer that could be blocking this in your browser?

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
I tried from other computer and its the same error but without the karspersky problem.




<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>504 Gateway Timeout</title>

</head><body>

<h1>Gateway Timeout</h1>

<p>The gateway did not receive a timely response

from the upstream server or application.</p>

<p>Additionally, a 504 Gateway Timeout

error was encountered while trying to use an ErrorDocument to handle the request.</p>

</body></html>


YUI.add("io-base",function(e,t){function o(t){var n=this;n._uid="io:"+s++,n._init(t),e.io._map[n._uid]=n}var n=["start","complete","end","success","failure","progress"],r=["status","statusText","responseText","responseXML"],i=e.config.win,s=0;o.prototype={_id:0,_headers:{"X-Requested-With":"XMLHttpRequest"},_timeout:{},_init:function(t){var r=this,i,s;r.cfg=t||{},e.augment(r,e.EventTarget);for(i=0,s=n.length;i<s;++i)r.publish("io:"+n[i],e.merge({broadcast:1},t)),r.publish("io-trn:"+n[i],t)},_create:function(t,n){var r=this,s={id:e.Lang.isNumberНе?n:r._id++,uid:r._uid},o=t.xdr?t.xdr.use:null,u=t.form&&t.form.upload?"iframe":null,a;return o==="native"&&(o=e.UA.ie&&!l?"xdr":null,r.setHeader("X-Requested-With")),a=o||u,s=a?e.merge(e.IO.customTransport(a),s):e.merge(e.IO.defaultTransport(),s),s.notify&&(t.notify=function(e,t,n){r.notify(e,t,n)}),a||i&&i.FormData&&t.data instanceof i.FormData&&(s.c.upload.onprogress=function(e){r.progress(s,e,t)},s.c.onload=function(e){r.load(s,e,t)},s.c.onerror=function(e){r.error(s,e,t)},s.upload=!0),s},_destroy:function(t){i&&!t.notify&&!t.xdr&&(u&&!t.upload?t.c.onreadystatechange=null:t.upload?(t.c.upload.onprogress=null,t.c.onload=null,t.c.onerror=null):e.UA.ie&&!t.e&&t.c.abort()),t=t.c=null},_evt:function(t,r,i){var s=this,o,u=i.arguments,a=s.cfg.emitFacade,f="io:"+t,l="io-trn:"+t;this.detach(l),r.e&&(r.c={status:0,statusText:r.e}),o=[a?{id:r.id,data:r.c,cfg:i,arguments:u}:r.id],a||(t===n[0]||t===n[2]?u&&o.push(u)тъженr.evt?o.push(r.evt):o.push(r.c),u&&o.push(u))),o.unshift(f),s.fire.apply(s,o),i.on&&(o[0]=l,s.once(l,i.on[t],i.context||e),s.fire.apply(s,o))},start:function(e,t){this._evt(n[0],e,t)},complete:function(e,t){this._evt(n[1],e,t)},end:function(e,t){this._evt(n[2],e,t),this._destroy(e)},success:function(e,t){this._evt(n[3],e,t),this.end(e,t)},failure:function(e,t){this._evt(n[4],e,t),this.end(e,t)},progress:function(e,t,r){e.evt=t,this._evt(n[5],e,r)},load:function(e,t,r){e.evt=t.target,this._evt(n[1],e,r)},error:function(e,t,r){e.evt=t,this._evt(n[4],e,r)},_retry:function(e,t,n){return this._destroy(e),n.xdr.use="flash",this.send(t,n,e.id)},_concat:function(e,t){return e+=(e.indexOf("?")===-1?"?":"&")+t,e},setHeader:function(e,t){t?this._headers[e]=t:delete this._headers[e]},_setHeaders:function(t,n){n=e.merge(this._headers,n),e.Object.each(n,function(e,r){e!=="disable"&&t.setRequestHeader(r,n[r])})},_startTimeout:function(e,t){var n=this;n._timeout[e.id]=setTimeout(function(){n._abort(e,"timeout")},t)},_clearTimeout:function(e){clearTimeout(this._timeout[e]),delete this._timeout[e]},_result:function(e,t){var n;try{n=e.c.status}catch(r){n=0}n>=200&&n<300||n===304||n===1223?this.success(e,t):this.failure(e,t)},_rS:function(e,t){var n=this;e.c.readyState===4&&(t.timeout&&n._clearTimeout(e.id),setTimeout(function(){n.complete(e,t),n._result(e,t)},0))},_abort:function(e,t){e&&e.c&&(e.e=t,e.c.abort())},send:function(t,n,i){var s,o,u,a,f,c,h=this,p=t,d={};n=n?e.ObjectНе:{},s=h._create(n,i),o=n.method?n.method.toUpperCase():"GET",f=n.sync,c=n.data,e.Lang.isObject(c)&&!c.nodeType&&!s.upload&&e.QueryString&&e.QueryString.stringify&&(n.data=c=e.QueryString.stringify(c));if(n.form){if(n.form.upload)return h.upload(s,t,n);c=h._serialize(n.form,c)}c||(c="");if(c)switch(o){case"GET":case"HEAD":case"DELETE":p=h._concat(p,c),c="";break;case"POST":case"PUT":n.headers=e.merge({"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},n.headers)}if(s.xdr)return h.xdr(p,s,n);if(s.notify)return s.c.send(s,t,n);!f&&!s.upload&&(s.c.onreadystatechange=function(){h._rS(s,n)});try{s.c.open(o,p,!f,n.username||null,n.password||null),h._setHeaders(s.c,n.headers||{}),h.start(s,n),n.xdr&&n.xdr.credentials&&l&&(s.c.withCredentials=!0),s.c.send(c);if(f){for(u=0,a=r.length;u<a;++u)d[r[u]]=s.c[r[u]];return d.getAllResponseHeaders=function(){return s.c.getAllResponseHeaders()},d.getResponseHeader=function(e){return s.c.getResponseHeader(e)},h.complete(s,n),h._result(s,n),d}}catch(v){if(s.xdr)return h._retry(s,t,n);h.complete(s,n),h._result(s,n)}return n.timeout&&h._startTimeout(s,n.timeout),{id:s.id,abort:function(){return s.c?h._abort(s,"abort"):!1},isInProgress:function(){return s.c?s.c.readyState%4:!1},io:h}}},e.io=function(t,n){var r=e.io._map["io:0"]||new o;return r.send.apply(r,[t,n])},e.io.header=function(t,n){var r=e.io._map["io:0"]||new o;r.setHeader(t,n)},e.IO=o,e.io._map={};var u=i&&i.XMLHttpRequest,a=i&&i.XDomainRequest,f=i&&i.ActiveXObject,l=u&&"withCredentials"in new XMLHttpRequest;e.mix(e.IO,{_default:"xhr",defaultTransport:function(t){if(!t){var n={c:e.IO.transports[e.IO._default](),notify:e.IO._default==="xhr"?!1:!0};return n}e.IO._default=t},transports:{xhr:function(){return u?new XMLHttpRequest:f?new ActiveXObject("Microsoft.XMLHTTP"):null},xdr:function(){return a?new XDomainRequest:null},iframe:function(){return{}},flash:null,nodejs:null},customTransport:function(t){var n={c:e.IO.transports[t]()};return n[t==="xdr"||t==="flash"?"xdr":"notify"]=!0,n}}),e.mix(e.IO.prototype,{notify:function(e,t,n){var r=this;switch(e){case"timeout":case"abort":case"transport error":t.c={status:0,statusText:e},e="failure";default:r[e].apply(r,[t,n])}}})},"3.17.2",{requires:["event-custom-base","querystring-stringify-simple"]});


In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Matt T -
What web server are you using? Apache or nginx? Or are you using shared hosting?

You probably need to increase the maximum file upload size in your web server software and/or PHP. See below link, which focuses mainly on Apache and PHP.

In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

I can see two things in your latest screenshot 1) the backup file appears to be 715.7 MB and 2) the XHR request is getting a 504 Gateway Timeout after 5 minutes. So maybe the the problem is that because the course backup is large a timeout is being exceeded.

Check PHP's max_execution_time, shown in PHP info. This may be 300 (i.e. 5 minutes). You could try doubling it.

In PHP info also check Server API, is it "FPM/FastCGI"? If so, then the next thing to check is Apache's TimeOut setting and try doubling that. This will be set in a .conf file somewhere, you may need to use grep if there are many files to search.

When changing any settings you probably need to reload or restart the corresponding service (e.g. systemctl restart httpd or systemctl restart php-fpm).

If your server is managed for you then you may need to contact the hosting provider for assistance with this.

If I'm correct about the size of the course backup you may want to try using Moosh to perform the restore at the command line as this avoids some issues with timeouts.

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
I already changed the max_execution_time and the same error happens.

these are the actual settings for php.ini:

display_errors = On
max_execution_time = 10000
max_input_time = 10000
max_input_vars = 10000
memory_limit = 900M
post_max_size = 900M
session.gc_maxlifetime = 10000
session.save_path = "/var/cpanel/php/sessions/ea-php70"
upload_max_filesize = 900M
zlib.output_compression = On


I can't find server api ... or where to change apache's timeout settings
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

Server API is shown in Site administration ▸ Server ▸ PHP info?:

Cropped screenshot of PHP Info with "Server API: FPM/FastCGI" highlighted.

If your site is hosted on a managed service that you use a web interface to manage (e.g. cPanel) then you may need to contact the hosting company to find out how to change Apache's TimeOut (they may not allow this).

To explain, if Apache is using Server API: FPM/FastCGI then when Apache runs some PHP it passes it to the FPM process. FPM runs the PHP then sends the results to Apache. But if the PHP takes a long time (for example when restoring a large course backup) then Apache may give up waiting and show the 503 Service Unavailable error instead. TimeOut controls how long Apache waits for FPM to run the PHP.

If Server API is not FPM/FastCGI (e.g. if it's Apache 2.0 Handler) then the problem may be something else and changing the Apache TimeOut may not help.

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Josefina Osán -
In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

I asked about PHP's Server API value, once and again, but you won't tell us.

As far as I'm aware the problem is: during an attempted restore of a large course backup (715.7 MB) the web server (not Moodle) is returning an error: 504 Gateway Timeout. We don't know why but it may be because the size of the course backup means that something is taking longer than is allowed (some timeout setting is exceeded).

It may be that your Moodle site needs a server with a better specification.

If you're desperate to fix this maybe you need to consider some commercial support options.

In reply to Josefina Osán

Re: Unexpected end of JSON input after migrating/upgrading

от Anze Pratnemer -
Try to update to latest Moodle 3.10, last week similar problem was fixed..
In reply to Anze Pratnemer

Re: Unexpected end of JSON input after migrating/upgrading

от Mark Rosthorn -

I have experienced 'Unexpected token < in JSON at position 0 syntax error message when clicking on 'Enrol users' button in a course.

Happens when visiting server externally but not when visiting local ip/localhost.

I un-ticked caching javascript and it now works okay. 

Any advice whether a firewall would be causing this would be appreciated and maybe a solution.

platform: Apache mysql (8.0.23-0ubuntu0.20.04.1) PHP 7.4 all up to date and new install of 3.10.2 with no plugins added yet.

In reply to Mark Rosthorn

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

Happens when visiting server externally but not when visiting local ip/localhost – do you mean when accessing Moodle with different URLs? Or that internally with the same URL but using a different IP address?

Can you tell if this is with the same /lib/ajax/service.php?sesskey=…&info=core_get_fragment request as the OP reported? You can use your browser's developer tools (for example Network Monitor in Firefox) to look for this URL and see what the response body is. It should start:

[{"error":false,"data":{"html":"...

Assuming the site is HTTPS, is the certificate installed on the server, or on a device in front of the server? I noticed on my site the Content-Type header is text/html on my test site, whereas it surely should be application/json. I wondered if something might object to that (I'm thinking out loud – I've got not idea what would do that).

In reply to Leon Stringer

Re: Unexpected end of JSON input after migrating/upgrading

от Mark Rosthorn -
The certificate is loaded on a device in front of server. When I switch off caching of javascript in Moodle config I can get external access to work but not when visiting internally.
Tried adding.. into sites-available/enabled area of apache2 and loaded it.
#Initialize mod_rewrite
RewriteEngine On FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
this does same only works externally not internally on correct domain.
Sorry don't get the network reporting bit of your message - I use chrome dev tools and just get the error popping up but no hint as to what it doesn't find. Although the error is saying that json return is starting with a '<' so html being returned when it expects a json starter.
Attachment error_LI.jpg
In reply to Mark Rosthorn

Re: Unexpected end of JSON input after migrating/upgrading

от Leon Stringer -
Снимка на Core developers Снимка на Particularly helpful Moodlers

The main request made when Enrol users is clicked is /lib/ajax/service.php?sesskey=…&info=core_get_fragment. Hopefully you can find this in the list of requests:

Cropped screenshot of Chrome developer tools with request "service.php?sesskey=...&info=core_get_fragment" highlighted

If you click on it in your browser's developer tools you should be able to see the response and whether it contains something not JSON, possibly HTML as you say. It may even contains information that helps solve this. If the response to that request looks okay, you'll have to check any other requests (there may only be this one).

If the certificate is in front of the server and internal connections are bypassing this then I had wondered if something could be inspecting and changing the contents mid-stream. That said Moodle should only have one URL and that would be HTTPS (ideally) or HTTP but not both, and HTTPS would prevent modification of the stream (unless there was some MITM involved).

I can't think why switching Cache Javascript off would affect this. The only change I can see is that a JavaScript link in the returned fragment (lib/form/form.js) is set to use a non-cached copy.