Request.JSON.Ex
sending a JSON request to the jsFiddle backend. Later on parse and display the data.
by sanford
HTML
<div class='wrapper'>
<p>JSON will be received in 3 seconds</p>
<ul id='post'></ul>
</div>http://jsfiddle.broadleafsystems.com/sanford/pUeTs/#update
CSS
body {
font-family: Helvetica, Sans, Arial;
}
p, ul {
padding: 10px;
}
ul {
margin: 5px;
border: 2px dashed #999;
}
JavaScript
Request.JSON.Ex = new Class({
Extends: Request.JSON
, moreData: {
json: {
alwayssendme: 1
}
}
, initialize: function(options){
Object.merge( ( options.data || {} ), this.moreData );
options.data.json = JSON.encode( options.data.json );
this.parent(options);
}
});
var iixhr = new Request.JSON.Ex({
url: '/echo/json/',
data: {
json: {
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
},
delay: 1
},
onSuccess: function(response) {
show_response(response, $('post'));
}
}).send();
show_response = function(obj, result) {
$H(obj).each(function(v, k) {
new Element('li', {
text: k + ': ' + v
}).inject(result);
});
result.highlight();
};