adrianvlupu
6/28/2013 - 8:43 AM

JSONP js wrapper

JSONP js wrapper

var JSONP = {
    _jsonpcallbacks: {},
    request: function (url, data, callback) {
        var callbackName = Math.random();
        Ripple._jsonpcallbacks[callbackName] = callback;
        var script = document.createElement('script');
        script.src = url + '?callback=' + callbackName + '&data=' + encodeURIComponent(JSON.stringify(data));
        script.type = 'text/javascript';
        document.getElementsByTagName('head')[0].appendChild(script);
    }
}
JSONP.request('http://localhost:51097/channel.ashx', {name:'adi'}, function(d){
    console.log(d);
});