› Test

Small example for the usage of the SeedFinder JSON API

This is a small example for real, but it will show you how you can use our API to create own applications for your website. For this example we use bothe APIs, the one for the the IDs and the StrainInfo-Api.

OK, here we go...

  • 1.: Our example will get at first the Breeder/Strain-ID JSON with a <script> tag in the header of the page. This will result (because of the parameter &output=1 in the url) in a Javascript-Object called BREEDER.
  • 2.: Out of this object we can generate very easily our small select-boxes for the breeders and strains. For this we have added the functions selectbreederform() and selectseedform().
  • 3.: If a strain was selected, the function loadStrainInfo() will be called and get the info with the help of jQuery's $.ajax() function from the SeedFinder StrainInfo-Api. As you see its with the JSONP-extension, so it also will work cross-domain. The function also parse the given data and will output the name, the breeders name and the description directly into the html-page.
  • Thats all, here the live-example - below you will find the code to test byself.

Test it right now:

Lets test

Click here to show a formular for breeders, then select a strain and read in the actual info!

The code for the example:

In the header:

The folloing code have to be stored in the header between <head> and </head>

<script src="jquery.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="http://en.seedfinder.eu/api/json/ids.json?output=1&strains=1"></script>

In the body:

The folloing code can be pasted somewhere onto the page between <body> and </body>

<script type="text/javascript">
function loadStrainInfo() {
   document.getElementById('TestTitle').innerHTML = '...please wait while loading';
   document.getElementById('TestDescr').innerHTML = '';
   var br = document.getElementById('breeder').value;
   var str = document.getElementById('strains').value;
   var thedata = 'br=' + br + '&str=' + str + '&output=2';
   $.ajax({
    dataType: 'jsonp',
    jsonp: 'jsonp_callback',
    url: 'http://en.seedfinder.eu/api/json/strain.json',
    data: thedata,
    success: function (STRAIN) {
      $('.TestTitle').html(STRAIN.name + ' (from ' + STRAIN.brinfo.name + ')');
      $('.TestDescr').html(STRAIN.brinfo.descr);
      }
   });
};

function selectseedform() {
   document.getElementById('TestTitle').innerHTML = '';
   document.getElementById('TestDescr').innerHTML = '';
   var thebreeder = document.getElementById('breeder').value;
   var strainselect = '<select id="strains" name="strains" size="1" onChange="loadStrainInfo();">\n   <option value="nix" id="nix" name="nix" selected="selected">...select a strain</option>';
   for(var bree in BREEDER) {
      if(bree == thebreeder) {
         for(var strainid in BREEDER[bree].strains) {
            strainselect = strainselect + '\n   <option value="' + strainid + '" id="' + strainid + '" name="' + strainid + '">' + BREEDER[bree].strains[strainid] + '</option>';
            }
         break;
         }
      }
   document.getElementById('strainp').innerHTML = strainselect + '</select>';
   }

function selectbreederform() {
   var breeselect = '<select id="breeder" name="breeder" size="1" onChange="selectseedform();">\n   <option value="nix" id="nix" name="nix" selected="selected">please select a breeder</option>';
   for(var bree in BREEDER) {
      breeselect = breeselect + '\n   <option value="' + bree + '" id="' + bree + '" name="' + bree + '">' + BREEDER[bree].name + '</option>';
      }
   document.getElementById('breederp').innerHTML = breeselect + '</select>';
   }
</script>

<p>
   <span id="breederp"></span>
   <span id="strainp"></span>
</p>
<h1 id="TestTitle" class="TestTitle">Lets test</h1>
<p id="TestDescr" class="TestDescr"><a href="javascript:selectbreederform();" title="test">Click here</a> to show a formular for breeders, then select a strain and read in the actual info!</p>

WICHTIG

Bitte beachten: Um unsere JSON API zu nutzen musst du zuvor hier im User-Bereich deine Domain(s) verifizieren!
Kommt die Abfrage von einer unregistrierten Domain wird ein Error 403 ausgeliefert!


Creative Commons BY-NC-SA 3.0 License Mit Hilfe der SeedFinder API bist du in der Lage unsere Daten für deine eigenen Applikationen und Widgets zu benutzen und kannst unsere Informationen direkt in deine Homepage einbinden. Das Ganze ist im Rahmen unserer Lizenz völlig kostenlos, wir behalten uns aber das Recht vor, bei zu enormen Traffic oder sonstigem ausfallendem Verhalten den Zugriff zu beschränken oder zu blocken. Um informiert zu bleiben wirf bitte ein Auge auf unseren Newsflash und/oder verknüpfe eine Email-Adresse mit deinem User-Account, damit wir dich im Zweifel erreichen können. Falls du keine Links zu uns setzen möchtest, oder eine kommerzielle Seite betreibst, melde dich bitte vorher bei uns. »» Alle Daten stehen unter einer Creative Commons BY-NC-SA 3.0 Lizenz