2012-09-11, 22:17
Please help....
I have read 228 pages of the JSON development thread twice over as well as covered other threads with searches.
I am yet to find a solution to my issue.
All I'm after is a simple way to POST JSON commands via Javascript.
I have tried creating functions, tried JQuery and AJAX,
I have seen and written that much code in the last 2 weeks that I feel I'm loosing brain cells at an extremely high rate.
In the old HTTP API i did it this way:
Using the BuiltIn commands.
I am limited to Javascript ( no python ) it is coded for a Home Automation box (Please don't look away!)
It says it supports jQuery and I've treid to utilize code from AWX's git with no luck.
I can map most direct commands via TCP, but what I'm ideally after is a bit of Javascript that pulls info of currently playing item.
If I can just get the code to work with a simple command, I would be able to manipulate it to send the correct command to get the info.
Here is a sample of code I tried:
Hope you can help....
I have read 228 pages of the JSON development thread twice over as well as covered other threads with searches.
I am yet to find a solution to my issue.
All I'm after is a simple way to POST JSON commands via Javascript.
I have tried creating functions, tried JQuery and AJAX,
I have seen and written that much code in the last 2 weeks that I feel I'm loosing brain cells at an extremely high rate.
In the old HTTP API i did it this way:
Code:
function xbmc(command){
var xmlhttp = new XMLHttpRequest();
var url = "http://";
var end = "/xbmcCmds/xbmcHttp";
var params = "command=ExecBuiltIn¶meter=";
xmlhttp.open("GET",url + XBMCnetwork.XBMCip +":"+ XBMCnetwork.XBMCport + end +"?"+ params + command, true);
xmlhttp.send(null);
}
Using the BuiltIn commands.
I am limited to Javascript ( no python ) it is coded for a Home Automation box (Please don't look away!)
It says it supports jQuery and I've treid to utilize code from AWX's git with no luck.
I can map most direct commands via TCP, but what I'm ideally after is a bit of Javascript that pulls info of currently playing item.
If I can just get the code to work with a simple command, I would be able to manipulate it to send the correct command to get the info.
Here is a sample of code I tried:
Code:
function xbmc(command){
var xmlhttp = new XMLHttpRequest();
var ip = XBMCip;
var port = XBMCport;
var url = "http://"+ ip +":"+ port +"/jsonrpc";
var params = '{"jsonrpc": "2.0", "method": "Input.Left", "id": "1"}';
xmlhttp.open("POST", url, false);
xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
xmlhttp.send('{"jsonrpc": "2.0", "method": "Input.Left", "id": "1"}');
}
}
Hope you can help....