I have a code which makes an ajax call, which has a callback. Is there a way i can replace the callback with an event emitter.
Below is my code.
 var _getPoll = function(params){
    var url = "http://localhost/poll"
    console.log(url);
    request({
        headers: {
            accept: 'application/json'
        },
        uri: url,
        method: 'GET'
    }, function(err, response, body){
        body = JSON.parse(body);
        console.log(body);
    })
}
Is it possible to replace the callback with an EventEmitter like below.
function(err, response, body){
    body = JSON.parse(body);
    console.log(body);
}
Replace
this.emit('jsonResponse', err, response, body);
 
     
    