June 30, 2009, 1 Comment
When prototyping, it’s handy to use a plain text file that contains JSON instead of generating it in code.
But consuming JSON data from JavaScript works better when it’s served with the correct application/json mimetype.
Using the PHP wrapper below, that plain text file is being served correctly.
By providing the optional jsonp parameter, the JSON can also returned as JSONP.
The script may also be used as a proxy to get JSON data from another domain to prevent crossdomain scripting errors.
<?php $url = $_REQUEST['url']; if ($url) { $data = file_get_contents($url); } else { echo "Please provide the 'url' parameter."; return; } $jsonp = $_REQUEST['jsonp']; if ($jsonp) { $data = $jsonp . "(" . $data . ");"; } header('Content-type: application/json'); echo $data; ?>
Usage examples:
(more…)
June 16, 2009, No Comments
Host 6pp_vm is a virtual machine that runs on host kvdb.net. The usual steps for connecting to 6pp_vm from my laptop:
kvdb@laptop:$ ssh kvdb.net # Type password kvdb@kvdb:$ ssh 6pp_vm # Type password kvdb@6pp:$
The goal is a login process reduced to:
kvdb@laptop:$ ssh 6pp_vm kvdb@6pp:$
June 16, 2009, 1 Comment
On this blog, I’ll post technical notes so I won’t forget them. You might find them useful.