Json request with jQuery don't be evil'

Thu, 10/08/2009 - 10:20

Jesus how complex can it be!  For our hyves/facebook gadget we needed to fetch some json from our website. After getting the < don't be evil' > message for a while we figured it out.

If this is your call:
function getJson() {
   
$.getJSON(http://www.yourdomain.com/hyvesapp/json?callback=?,
            function(data){
              
alert("got here"+data.name);
    });
}

In your code you have to do some things to get this working, jQuery adds a function name to the ? at the end (see the manual) so you need to readout the callback GET param in your script to get it to work.

 

This is the function is used:
function hyvesappCreatejson(){
    header("Content-Type: application/json;");
    $obj = new stdClass;
    $obj->name = "yourname";
    $obj->url = "www.gijs.com";

    echo $_GET['callback'].'('.json_encode($obj).')';exit;
}

Hope this helps.

Tweet
  1. james123 on Wed, 02/17/2010 - 08:36
  2. jamessmithforum on Tue, 02/02/2010 - 11:06
  3. Post new comment

    CAPTCHA
    This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Infomation

My name is Gijs Epping i am a a dutch webdeveloper currently working for eFocus. I use Typo3 and Drupal on most of my work an freelance projects.