Ajax Testing with JSFiddle

by bgrins

HTML

<div class='wrapper'>
    <p>JSONP is loaded from different domain</p>
    <ul id='post'></ul>
</div>

CSS

body {
    font-family: Lucida Sans, Arial;
}
p, ul {
    padding: 10px;
}
ul {
    margin: 5px;
    border: 2px dashed #999;
}

JavaScript

$.getJSON('http://jsfiddle.net/echo/jsonp/?callback=?', {
        text: 'some text',   
        par1: 'another text',
        delay: 1 
    },
    function(data) {
        showSuccess(data);
    }
);

function each(o, fn) {
    var results = [];
    for (var i in o) {
        results.push(fn(i, o[i]));
    }
    return results;
}

function showSuccess(data) {
    var templated = each(data, function(name, val) {
        return "<li>" + name + ": " + val + "</li>"; 
    });
    console.log(templated.join(''));
    $("#post").html('<ul>' + templated.join('') + '</ul>');
}