0

I have a plugin where I am trying to re-initialize the javascript events after the ajax call. After the done method, all the events are lost.

I am trying to re-initialize the init method.

 function Plugin(element, options) {
 this.el = element;
 this.$el = $(element);
 this.settings = $.extend({}, defaults, options);
 this._name = pluginName;
 this.ns = '.myPluginName';
 this.init();
}

Plugin.prototype = {
init: function();

var bind = this;
var somelink = bind.$el.find('.mylink');

var functionstartshere = function(){
    // all the function starts here


    //after the ajax call the new page looses all the event handlers
    var jqxhr = $.ajax( "example.php" )
      .done(function() {
        //adding my function here
        //how do i re-initialize the events
        //how do I call the init/ functionstartshere to put the events back
      })
      .fail(function() {
        alert( "error" );
      })    

}

some.on("click", functonstartshere);
user2950017
  • 35
  • 1
  • 11
  • Bind your event using `on` or just call your init function?! What exactly is your problem? – LJᛃ Nov 28 '14 at 00:02
  • I am already using on to bind the event some.on("click", functionstartshere). What is happening is after the ajax call is made, all the events are lost. I need to re-initialize the events. – user2950017 Nov 28 '14 at 00:36
  • Why are they lost? Are you replacing your DOM nodes? I was talking about the `on("event", ".selector", handler)` signature of on. – LJᛃ Nov 28 '14 at 00:40
  • I am replacing the dom by using jquery replace method and every time Ajax is using all the events are lost and have to re-initialize again. There is only once click event which calls the function. Everything is happening inside that function. – user2950017 Nov 28 '14 at 00:49
  • my situation is something like this http://stackoverflow.com/questions/12148284/reinitiate-events-listeners-javascript-jquery but instead of body its binded to the button click. – user2950017 Nov 28 '14 at 02:05
  • Well then read the answer there, or read the doc [jQuery.on](http://api.jquery.com/on/) I already gave you two solutions to your question. I wont write the code for you. – LJᛃ Nov 28 '14 at 03:03

0 Answers0