getting CORS blocking JSON request (solved)

Post Reply
mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

getting CORS blocking JSON request (solved)

Post by mtrax » Sun Nov 17, 2019 4:08 am

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);
				}
        });
Last edited by mtrax on Tue Nov 19, 2019 6:08 am, edited 1 time in total.

User avatar
bill6502
Developer
Posts: 1711
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: getting CORS blocking JSON request

Post by bill6502 » Sun Nov 17, 2019 7:29 pm

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.

mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

Re: getting CORS blocking JSON request

Post by mtrax » Sun Nov 17, 2019 7:35 pm

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?
Last edited by mtrax on Sun Nov 17, 2019 7:45 pm, edited 1 time in total.

User avatar
bill6502
Developer
Posts: 1711
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: getting CORS blocking JSON request

Post by bill6502 » Sun Nov 17, 2019 7:42 pm

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.

mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

Re: getting CORS blocking JSON request

Post by mtrax » Sun Nov 17, 2019 7:46 pm

I don't find any matches for that name in settings table

User avatar
bill6502
Developer
Posts: 1711
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: getting CORS blocking JSON request

Post by bill6502 » Sun Nov 17, 2019 7:51 pm

Correct, the setting is for expanding the defaults. Are the any messages in the logs.
Check before changing the DB.

mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

Re: getting CORS blocking JSON request

Post by mtrax » Sun Nov 17, 2019 8:16 pm

backend log message

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

User avatar
bill6502
Developer
Posts: 1711
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: getting CORS blocking JSON request

Post by bill6502 » Sun Nov 17, 2019 8:38 pm

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.

mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

Re: getting CORS blocking JSON request

Post by mtrax » Sun Nov 17, 2019 10:53 pm

Jsonp will send xml

mtrax
Junior
Posts: 40
Joined: Sat Aug 16, 2014 6:44 am
Australia

Re: getting CORS blocking JSON request

Post by mtrax » Tue Nov 19, 2019 6:07 am

solved,by inserting AllowedOriginsList value in settings table.

Post Reply