I am trying to generate widget through javascript, that fetch the result from the server and display it.
This is how i am doing:
var Widgets = function( element, options ) {
this.ele = document.getElementById( element );
this.options = extend({}, this.options);
extend( this.options, options );
this._init();
};
Widgets.prototype = {
options: {
userKey: 'xxxxxxxxxxxxxxxxxx'
},
_init: function() {
// Send request to Server
this.sendRequestToServer();
},
sendRequestToServer: function() {
var script = document.createElement('script');
script.src = 'http://example.localhost/api/get_widget/'+this.options.userKey+'?callback=onFetchComplete';
document.getElementsByTagName('head')[0].appendChild(script);
},
// callback not working
onFetchComplete: function() {
}
};
My problem is callback=onFetchComplete
, my method in not callable with callback request. I know that this will work with when i call with this.onFetchComplete
. Can anyone please suggest the right way to do this through the same prototyping approach?