Minified - Request / Echo
by tjansen
HTML
<script src="http://minifiedjs.com/download/minified-src.js"></script>
<div class='wrapper'>
<p>JSON will be received in 3 seconds</p>
<ul id='post'></ul>
</div>
CSS
body {
font-family: Helvetica, Sans, Arial;
}
p, ul {
padding: 10px;
}
ul {
margin: 5px;
border: 2px dashed #999;
list-style-type: none;
}
JavaScript
var MINI = require('minified');
var $ = MINI.$, $$ = MINI.$$, EE = MINI.EE;
// JSON example based on Mootools example, translated to Minified:
// http://jsfiddle.net/zalun/QsHw4/light/
$(function() {
$.request('post', '/echo/json/', {
json: $.toJSON({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
}).then(function(response) {
showResponse($.parseJSON(response), $('#post'));
});
function showResponse(obj, result) {
for (k in obj)
result.add(EE('li', k + ': ' + obj[k]));
result.set({$backgroundColor: '#FFFFCC'}).animate({$backgroundColor: '#fff'});
};
});