- GetPlayerDataByPIN : this function returns a JSON structure containing the data of the player referred by the PIN. You can invoke it directly :
http://www.europeangodatabase.eu/EGD/GetPlayerDataByPIN.php?pin=12098053
- GetPlayerDataByData : this function, much more interesting, returns a JSON structure containing an array of all the players who match the request. You can specify at least lastname and/or country, but you can also refine the search with name and club. For instance:
http://www.europeangodatabase.eu/EGD/GetPlayerDataByData.php?lastname=poda&name=an
The only problem is that due to security issues, in both Internet Explorer and FireFox, the AJAX calls are not allowed to make cross-domain, cross-protocol, or cross-port requests. In other words, if you put into your web pages a standard AJAX call (i.e.: using the XMLHttpRequest object), your browser refuses to execute it unless the called url resides in the same domain as the calling page, This means that you cannot call the two EGD scripts directly from inside an HTML page in your own domain.
Luckily, it's quite easy to work around this issue. Assuming that you can write some server-side code in your domain (which is almost certainly true, since you are thinking of writing a web form), you can write an extremely simple AJAX proxy page, no longer than one line, which takes care of doing the call to the EGD scripts and returning back to your page the result.
For instance, if you are using PHP as server-side language, you can write this ProxyAjax.php file:
<?php
echo(file_get_contents($_GET['url']));
?>
Nothing else. If you are using server-side technologies other than PHP (such as .NET, Perl, JSP, ColdFusion, etc...) you want to do something similar, now you got the idea.
If you are security conscious, note that, in order to prevent malicious use of this script, you may want to perform some checks on the URLs it is supposed to serve. Otherwise, everybody may call it to get anonymous access to third-party pages.
So your ProxyAjax.php can look something like this:
<?php
if (substr($_GET['url'],0,33)=='http://www.europeangodatabase.eu/')
{ echo(file_get_contents($_GET['url']));
}
else
{ echo('Illegal URL; your request has been logged');
// Do something here if you really want to log unauthorized accesses
}
?>
Now, you can simply make an AJAX call to this ProxyAjax.php file passing the url you actually wanted to call.
For instance, save in the main folder of your domain this PHP script, then try clicking:
you'll get exactly the same data that you would have got from the EGD script (please note that "%26" is the HTML code for the ampersand "&". I put it in order to prevent breaking the 'url' parameter).
Now, it's very simple to put all together :
- an HTML page with :
- a form with the player's fields
- some Javascript code used to ajax-launch the
ProxyAjax.phpscript.
- the tiny
ProxyAjax.phpscript
Demo
To see all this in action, look at the example below; try typing in some letters in the last name field, and see what happens: after the third letter, a combo appears with the list of all the players (if any) whose last names match the string typed in. Adding more letters, the search is dinamically refined. Select one of the entries clicking on it, and all the other fields will be automagically filled :