Web interface: JSON-RPC using JS
#1
Hi, I'd like to make my own web interface for xbmc and read through the wiki on the JSON-RPC. After that, I wrote a small script as a basis to communicate with XBMC.

Code:
var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://IP:8080/jsonrpc");
    xhr.onload = function(){ console.log(xhr.responseText) }
    xhr.send();

When I load this script into Chrome, it tells me that Origin null is not allowed by Access-Control-Allow-Origin and won't execute the request. The problem is that the domain which forms the origin of the request differs from the domain of the resource and that's not allowed.

What I just need is a little 'hello world' example of how to communicate with xbmc and I'll be ready to go.

Thanks in advance!
Reply
#2
BASSI3 Wrote:Hi, I'd like to make my own web interface for xbmc and read through the wiki on the JSON-RPC. After that, I wrote a small script as a basis to communicate with XBMC.

Code:
var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://IP:8080/jsonrpc");
    xhr.onload = function(){ console.log(xhr.responseText) }
    xhr.send();

When I load this script into Chrome, it tells me that Origin null is not allowed by Access-Control-Allow-Origin and won't execute the request. The problem is that the domain which forms the origin of the request differs from the domain of the resource and that's not allowed.

What I just need is a little 'hello world' example of how to communicate with xbmc and I'll be ready to go.

Thanks in advance!

This is a security issue.
Ajax will not make calls outside your domain.

You can fix this by making a php proxy file.
See http://jquery-howto.blogspot.com/2009/04...query.html for more information.

OK, for my question.
Now that I can load http:192.168.0.1:8080/jsonrpc what the hell do I do next? I have a controller working using the depreciated "xbmcCmds/xbmcHttp?command=" format, but I now want to do the same with JSON.
When I try anything, all I get back is "JSONRPC active and working"
How do I get JSON data out of the XBMC using java?
I'm sure it's simple, but having never used JSON before, I'm at a loss.
Reply
#3
Kudapucat Wrote:This is a security issue.
Ajax will not make calls outside your domain.

You can fix this by making a php proxy file.
See http://jquery-howto.blogspot.com/2009/04...query.html for more information.

OK, for my question.
Now that I can load http:192.168.0.1:8080/jsonrpc what the hell do I do next? I have a controller working using the depreciated "xbmcCmds/xbmcHttp?command=" format, but I now want to do the same with JSON.
When I try anything, all I get back is "JSONRPC active and working"
How do I get JSON data out of the XBMC using java?
I'm sure it's simple, but having never used JSON before, I'm at a loss.

You will probably need to import an external library. I would start here but I'm no java expert and there might be better libraries out there.

You will need to use a jsonrpc object and from it make your calls. Python example:
Code:
xbmc = jsonrpclib.Server(xbmc_json_address)
xbmc.Input.left()
Maraschino - github - website
Reply
#4
Hmmm sorry. I'm trying to use AJAX and JavaSCRIPT in a client-side processor.
JavaScript comes with an object that can be used for JSON.
I just don't know what to do, I can't see the data.
Do I need to post something to xbmcip:port/jsonrpc before I'll get data? What will the data look like if I don't process it? Just an XML style page?
Reply
#5
Kudapucat Wrote:Hmmm sorry. I'm trying to use AJAX and JavaSCRIPT in a client-side processor.
JavaScript comes with an object that can be used for JSON.
I just don't know what to do, I can't see the data.
Do I need to post something to xbmcip:port/jsonrpc before I'll get data? What will the data look like if I don't process it? Just an XML style page?

This might be useful for you -> http://barracudaserver.com/doc/WebServices/JRpcDoc.html

But the way I would do it is have a php page with all the methods you might need and assign them some get parameters like "?action=play" and when that is set call the appropriate php method for that. I do no think javascript alone with get you any results. A good php library for you would be XBMC-PHP-RPC
Maraschino - github - website
Reply
#6
Another option is to consider implementing JSON-RPC functionality over WebSocket with JSON parser and emitter and embedded JS engine.
Reply
#7
@Tom83 are you aware you just replied to an 11 year old post and the original conversation was had by people who probably arent around anymore?
Reply

Logout Mark Read Team Forum Stats Members Help
Web interface: JSON-RPC using JS0