Sending JSON-RPC Command from Javascript
#1
HI,

I need some help please.

I have create a script add-on that I want to execute from javascript.

If I sent the command using curl, it works perfectly, but I don't know how to send it from javascript using jQuery.

This is the curl statement that works:

Code:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.tv.msg"} }' http://10.4.1.73:80/jsonrpc

This is my javascript code:
Code:
$.ajax({
                    type: "POST",
                   contentType: "application/json",
                    data: {
                            "jsonrpc": "2.0",
                            "method": "Addons.ExecuteAddon",
                            "params": {"addonid": "script.tv.msg"}
                          },
                    dataType: "json",
                    //
                    success: alert("Success"),
                    error: alert("Failure")

                })

I get the following error:
Code:
"NetworkError: 404 Not Found - http://10.4.1.73/addons/plugin.webinterface.tvmsg/jsonrpc"

Obviously, I don't understand something

Can anybody please help?
Reply
#2
i suppose your url to jsonrpc is wrong. it's not at the location of your interface, well i am not 100% sure. what i am sure, that the code under it works in my case.
in your case it might be http://10.4.1.73/jsonrpc,
generally: http://ip:port/jsonrpc?optionalDescription
or just do it how i did it in the following code, which should work in any circumstances.

this might work:
Code:
jQuery.ajax({
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    type: "POST",
    async: true,
    'url': '/jsonrpc?whateever',
    'data': '{ "jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1 }',
    'dataType': 'json',
    'success': alert('Success'),
    'error': alert('Failure')
  });
Check out my plugin yarc, it's a web-remote optimised for all screen sizes (especially touch and small screen).
Reply
#3
Thanks, I have it working now 100%
Reply

Logout Mark Read Team Forum Stats Members Help
Sending JSON-RPC Command from Javascript0