Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created December 13, 2010 20:33
Show Gist options
  • Save mklabs/739557 to your computer and use it in GitHub Desktop.
Save mklabs/739557 to your computer and use it in GitHub Desktop.
<?php
header('content-type: application/json; charset=utf-8');
/* * /
$phi = array('okey' => 0, 'object' => array ("firstName"=> 'Philippe', 'lastName'=> 'Charriere'));
$j = array('okey' => 1, 'object' => array ('firstName'=> 'John', 'lastName'=> 'Resig'));
$v = array('okey' => 2, 'object' => array ('firstName'=> 'Linus', 'lastName'=> 'Torvald'));
$m = array('okey' => 3, 'object' => array ('firstName'=> 'Douglas', 'lastName'=> 'Crockford'));
/* */
$phi = array('okey' => 0, 'object' => '{"firstName": "Philippe", "lastName": "Charriere"}');
$j = array('okey' => 0, 'object' => '{"firstName": "John", "lastName": "Resig"}');
$v = array('okey' => 0, 'object' => '{"firstName": "Linus", "lastName": "Torvald"}');
$m = array('okey' => 0, 'object' => '{"firstName": "Douglas", "lastName": "Crockford"}');
$list = array ($phi, $j, $v, $m);
echo $_GET['callback'] . '(' . json_encode($list) . ');';
/* * /
list_return([{"okey":0,"object":"{\"firstName\": \"Philippe\", \"lastName\": \"Charriere\"}"},{"okey":0,"object":"{\"firstName\": \"John\", \"lastName\": \"Resig\"}"},{"okey":0,"object":"{\"firstName\": \"Linus\", \"lastName\": \"Torvald\"}"},{"okey":0,"object":"{\"firstName\": \"Douglas\", \"lastName\": \"Crockford\"}"}]);
/* */
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
</head>
<!--[if lt IE 7 ]> <body class="ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie7"> <![endif]-->
<!--[if IE 8 ]> <body class="ie8"> <![endif]-->
<!--[if IE 9 ]> <body class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <body> <!--<![endif]-->
<div id="container">
<header>
</header>
<div id="main">
<ul id="listofobjects"></ul>
</div>
<footer>
</footer>
</div>
<script>
(function(){
function list_return(return_values) {
console.log('list_return', this, arguments);
var myObject, current, l = return_values.length;
for (var i = 0; i < l; i++) {
current = return_values[i];
console.log(current);
myObject = JSON.parse(current.object);
console.log(current.okey);
console.log(myObject);
add_li('listofobjects', current.okey + ' ' + myObject.firstName + ' ' + myObject.lastName)
}
document.body.removeChild(document.getElementById("TMP2"));
}
function add_li(list, text) {
var list = document.getElementById(list);
var li = document.createElement("li");
li.innerHTML = text;
list.appendChild(li);
}
function list() {
var script = document.createElement('script');
script.src = "index.php?callback=list_return";
script.id = "TMP2";
document.body.appendChild(script);
}
// Globalify...
this.list = list;
this.list_return = list_return;
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment