The nothing
The nothing

Reputation: 308

Execute success ajax from method object via dynamic function

I need to run the success of ajax from a method function of object, this work when a pass to normal variable function

methodOne = function(data) {
  alert(data);
};

$(document).on('click', ".clichere", function() {
  var callback = function(){};
  callback = methodOne;
  runAjax({dispatch_ajax : "testing"}, callback );
    });

function runAjax(data, succFunction) {

  $.ajax({
      type: "POST",
      data: data,
      success: succFunction,
      error: function(error) {
          alert(JSON.stringify(error));
      },
  });

} 

this not work

var myapp = function() {
   this.listTableOptions = function(data) {
    alert(data);
   };
};


$(document).on('click', ".clichere", function() {

  obj = new myapp();

  runAjax({dispatch_ajax : "testing"}, obj.listTableOptions() );

});

I can't not get the data in myapp object

Upvotes: 1

Views: 29

Answers (1)

J Livengood
J Livengood

Reputation: 2738

You want to pass the function listTableOptions instead of executing it and passing the result so the following will work:

var myapp = function() {
   this.listTableOptions = function(data) {
    alert(data);
   };
};

$(document).on('click', ".clichere", function() {
  obj = new myapp();
  runAjax({dispatch_ajax : "testing"}, obj.listTableOptions );
});

Notice obj.listTableOptions instead of obj.listTableOptions()

Upvotes: 2

Related Questions