Welcome to openkapow Sign in | Join
in Search
.

Callback

Last post 08-21-2008, 3:26 PM by Nitin Gupta. 7 replies.
Sort Posts: Previous Next
  •  11-29-2006, 7:06 AM 5920

    Callback

    I wanna use the callback-style functionality that Yahoo's web services and many more have. With a callback function it would be easy to use robots from withing just plain javascript.
    Filed under: ,
  •  11-29-2006, 7:18 AM 5924 in reply to 5920

    Re: Callback

    I would like to know this as well, I want to use a javascript function to handle JSON from a REST robot.
  •  12-01-2006, 12:38 AM 5940 in reply to 5924

    Re: Callback

    To use a callback function you need to specify the GET parameter "json.callback" in the URL to the REST robot. For example you would have a URL like this:

    http://service.openkapow.com/...?resultformat=json&json.callbackFunction=myVeryOwnCallbackFunction&...

    Then you of course need to define the javascript funciton myVeryOwnCallbackFunction that takes one input parameter. This input parameter will be the JSON output from the REST robot.

     I hope that clarifies things a bit!
     


    "A robot on openkapow is worth two on the harddrive" - old saying

    WebHostNinja.com - price comparison for web hosting
    Digitalistic.com - mashup or die
    Filed under: ,
  •  12-01-2006, 2:59 AM 5946 in reply to 5940

    Re: Callback

    Thanks. Found that in javascript source code of the Personal Digg RSS demo. Nice.
  •  05-14-2007, 10:19 PM 10238 in reply to 5946

    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.
    .


  •  05-15-2007, 7:13 AM 10250 in reply to 10238

    Re: Callback

    Havent tried that with Opera, but I have had "problems" (acctually quite a good security feature) with both IE and Firefox when it comes to cross site HTTPRequests. You could avoid a page load by using the "dynamic script tag" approach and combine that with JSON and callback. A dynamic script tag is simply that you from javascript insert a new <script> tag that in turn calls an openkapow robot.

    "A robot on openkapow is worth two on the harddrive" - old saying

    WebHostNinja.com - price comparison for web hosting
    Digitalistic.com - mashup or die
  •  08-21-2008, 3:04 PM 20914 in reply to 10250

    Re: Callback

    Hi Andreas,

       When I do exactly this the response still returns a json object and does not wrap function name supplied as argument to the Json.callbackFunction parameter.


    Is there any configuration file that I should update on kapow to enable this?

     
    What I have seen work is if I enable callback function through the GUI and give it a static callback function name. In our case, the callback is not static.
     

     

  •  08-21-2008, 3:26 PM 20915 in reply to 20914

    Re: Callback

    I am seeing something similar, when I am trying to make callback function dynamic. AFAIK, kapow robomaker allows

    1. callback function to be dynamic (only if you don't hardcode it in robomaker callback function name), but in that case you will get bare minimum json object

    2. function name wrapped around returned json object, if you do hardcode that function name while enabling callback function in robot configuration.

    We are using robomaker 6.3(web 2.0 edition) and if there is any way making dynamic callmabck function name padded around returned json object, that will be great.

     

    Thanks

View as RSS news feed in XML
.
Copyright 2006, 2007 KapowTech.com All Rights Reserved Company | Contact | Terms | Privacy