Welcome to openkapow Sign in | Join
.

Re: Callback

  •  05-14-2007, 10:19 PM

    Re: Callback

    Thanks for the "Personal Digg RSS" demo using json and callbackFunction. However, this way of doing is limited, because it requires loading a page and then getting the result in json format. Making a second call requires to reload the page.

    In my case, I want to call a REST service from javascript without having to reload my html page. I guess that the most commonly accepted way to do it from javascript is to use AJAX functions with XMLHttpRequest functions.
    By the way, I use the library prototype.js to make simplified calls using AJAX. Details here.

    Here is my code, to paste inside a html page. Request_http could be triggered by hitting a button. Note: blabla.rest is fictional, any REST robot would do.

    <script type="text/javascript" src="prototype.js"></script>
    <script type='text/javascript'>
    function Request_http()
    {
    var url = 'http://service.openkapow.com/_ _ _ / blabla.rest';
    var pars='resultformat=json&xml.rootElementName=&html.title=&html.style.stylesheetLink=&header=yes&json.callbackFunction=';
    new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: myResponse });
    }

    function myResponse(originalRequest)
    {
    jsonRaw = originalRequest.responseText;
    jsonContent = eval("(" + jsonRaw + ")");
    alert(jsonContent);
    }
    </script>

    Unfortunately, this does not work. I bet that the problem is that I am trying to make an AJAX call from my personal server to Openkapow server. For security reasons, the browser (Opera in my case) probably blocks this call.

    Which leads me to the question: how can I call Openkapow REST robots from javascript with AJAX functions given that the 2 servers (OpenKapow's and mine) are separate?

    Note: I know that there is a way using PHP, but I want to stick to javascript and AJAX to keep it simple.
    .


View Complete Thread
.
Copyright 2006, 2007 KapowTech.com All Rights Reserved Company | Contact | Terms | Privacy