Page 1 of 1

getting CORS blocking JSON request (solved)

Posted: Sun Nov 17, 2019 4:08 am
by mtrax
I'm writing a simple AJAX request to retrieve upcoming recordings but I'm getting:
the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://mythbox:6544/Dvr/GetUpcomingList?count=3. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
is there something I need to do in my AJAX request?

Code: Select all

    $.ajax( {
		  url: "http://mythbox:6544/Dvr/GetUpcomingList", 
		  data: {"count": 3},
		  dataType: 'json',
		  crossDomain: true,

          success: function(response) {
            //var response = transport.responseText.evalJSON() || "no response text";	
				console.log(response);
				}
        });

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 7:29 pm
by bill6502
Hi,

I don't speak AJAX, but you can try: mythbackend --setverbose http:debug on mythbox (that
has the backend already running.) Then look in the backend log, perhaps /var/log/mythtv/mythbackend.log.

If the backend detects a CORS failure, there are logs for it. There's a setting to allow additional origins, if
that's what's required. "AllowedOriginsList", but there is no GUI for changing it.

I assume that http://mythbox:6544/Dvr/GetUpcomingList works from a browser/curl/wget...

Turn the extra logging off with: mythbackend --setverbose http:alert.

Maybe something like: https://stackoverflow.com/questions/190 ... low-origin
which suggests jsonp rather than json.

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 7:35 pm
by mtrax
Yes it works for curl and php but not for jquery Ajax request for json.
is the AllowedOriginsList setting in database somewhere how do insert /create?

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 7:42 pm
by bill6502
Yes, it's in settings, but isn't likely there as there are defaults.

Code: Select all

https://chromecast.mythtv.org,http://chromecast.mythtvcast.com
But I'd check the logs before going there.

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 7:46 pm
by mtrax
I don't find any matches for that name in settings table

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 7:51 pm
by bill6502
Correct, the setting is for expanding the defaults. Are the any messages in the logs.
Check before changing the DB.

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 8:16 pm
by mtrax
backend log message

(AddCORSHeaders) HTTPRequest: Cross-origin request received with origin (http://mythbox)

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 8:38 pm
by bill6502

Code: Select all

curl --data Key=AllowedOriginsList --data Value=commaSeparatedListIncludeingDefaultsAbove --data HostName=_GLOBAL_  localhost:6544/Myth/PutSetting
The CORS code was added some time ago but I don't recall the release v29, v30 and v31-Pre have it.
Mention your MythTV version if the above doesn't work.

I assume you tried jsonp and setting crossDomain: false and it still failed. Again, I don't speak AJAX.

Re: getting CORS blocking JSON request

Posted: Sun Nov 17, 2019 10:53 pm
by mtrax
Jsonp will send xml

Re: getting CORS blocking JSON request

Posted: Tue Nov 19, 2019 6:07 am
by mtrax
solved,by inserting AllowedOriginsList value in settings table.