new unsupported API question

Got a neat new template? Share it here!
Post Reply
bpwats
Newbie
Newbie
Posts: 28
Joined: May 16th, 2008, 10:13 am

new unsupported API question

Post by bpwats »

Hi all,

I am trying to interface with the new JSON API (trunk version) using prototype.js

The following index.html is served from Apache:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<link rel="stylesheet" type="text/css" media="all" href="css/style.css" />
	
	<script type="text/javascript" src="js/prototype.js"></script>

    <script type="text/javascript">
	var host = "192.168.25.12";
	var port = "8080";
	var apiCommand = "api?mode=version&output=json";
	var url = '/proxy?url=' + encodeURIComponent('http://192.168.25.12:8080/sabnzbd/api?mode=version&output=json');
	// notice the use of a proxy to circumvent the Same Origin Policy.
	
    var request = new Ajax.Updater('page-wrap',
									url,
									{ method:'get',
										onSuccess: function(transport){
											var json = transport.responseText.evalJSON();
										}
    });

    </script>

	<title>SABnzbD Prototype Status</title>
	
</head>

<body>

	<div id="page-wrap">
     	<h1>Reading JSON with Prototype</h1>
    </div>

</body>

</html>
However, it renders "Not Found
The requested URL /proxy was not found on this server."

When entering

Code: Select all

http://192.168.25.12:8080/sabnzbd/api?mode=version&output=json
in a browser, it responds properly with a file called api containing the JSON object.

Who could help me along?
TIA,
bpwats
Last edited by bpwats on January 6th, 2009, 5:35 pm, edited 1 time in total.
User avatar
inpheaux
Administrator
Administrator
Posts: 563
Joined: January 16th, 2008, 9:14 pm

Re: new unsupported API question

Post by inpheaux »

Yeah, if you're going to use ajax you either need to set up a proxy on the same machine SABnzbd lives on, or make your thing a template (so it's on the same port/ip as SABnzbd).

Or wait until Firefox 3.1, which supposedly removes this restriction.
bpwats
Newbie
Newbie
Posts: 28
Joined: May 16th, 2008, 10:13 am

Re: new unsupported API question

Post by bpwats »

Okay, pardon my ignorance for my question being indirectly related to SABnzbd.

I had to add the following to /etc/apache2/httpd.conf (above the last line)

Code: Select all

#
# Proxy Server directives. 
#
<IfModule mod_proxy.c>
    ProxyRequests On
    ProxyPreserveHost On

    ProxyStatus On
    <Location /status>
        SetHandler server-status

        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Location>

    ProxyPass    /sabnzbd    http://localhost:8080/sabnzbd
</IfModule>
Post Reply