Web interface: JSON-RPC using JS

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
BASSI3 Offline
Junior Member
Posts: 8
Joined: Dec 2010
Reputation: 0
Post: #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!
find quote
Kudapucat Offline
Junior Member
Posts: 2
Joined: Jan 2012
Reputation: 0
Post: #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.
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #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
find quote
Kudapucat Offline
Junior Member
Posts: 2
Joined: Jan 2012
Reputation: 0
Post: #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?
find quote
gugahoi Offline
Fan
Posts: 723
Joined: Aug 2009
Reputation: 5
Post: #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
find quote