My favorites | Sign in
Project Logo
                
Search
for
Updated Apr 16, 2008 by botelho.daniel
Labels: Documentation, Tutorial, API
GadgetRequest  
GadgetRequest allows to fetch content from one provided URL and feeds that content into the callback function.

Introduction

This class allows to fetch content from one provided URL and feeds that content into the callback function.

To create an GadgetRequest we need to call the constructor like this:

$gadget_request = new GadgetRequest('gadgetRequest','http://graargh.returnstrue.com/buh/fetchme.php');

Doing this we create an GadgetRequest Object identified by 'gadgetRequest' and that it will be made to the 'http://graargh.returnstrue.com/buh/fetchme.php' url. After creating the object we need to set it's content type like this:

$gadget_request->setMethod(GadgetMethodType::POST);

Here we are saying that the request will be as POST to the provided URL. Next we need to define what will be submited to the container and here we use something like this:

$gadget_request->setPostData(GadgetsIO::encodeValues('{ data1 : "test", data2 : 1234566 }',true));

Now to actually perform the Request we need to call the GadgetsIO class like this:

$this->gadget_response = GadgetsIO::makeRequest($gadget_request);
echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($gadget_request->->getJSRequestFunction()));

That it will return an GadgetResponse object that will be used in the view and the last line will say to the container to execute the this request when the gadget is loaded. In the view we can use this code:

//view
<div id="post">post</div>

<?php echo JSFunction::addJSOpenTag($gadget_response->getJSFunction()); ?>
  var text = <?php echo $gadget_response->getText(); ?>
  document.getElementById('post').innerHTML = text;
  <?php echo GadgetsWindow::adjustHeight(); ?>
<?php echo JSFunction::addJSCloseTag($gadget_response->getJSFunction()) ?>

This code will handle the response and set the div "post" with the content received by the container.

Classes related

Classes that extends GadgetRequest:

  • class TextGadgetRequest
  • class DomGadgetRequest
  • class FeedGadgetRequest
  • class JsonGadgetRequest


Sign in to add a comment
Hosted by Google Code