javascript - Passed function has a variable not working -


i have below javascript getting error: uncaught typeerror: responsehandler not function

var message = {     initialmessagelist: function(profile_id) {             $('.messages-list profile'+ profile_id).html = '<div class="message-loader profile"+ profile_id><i class="fa fa-spinner fa-spin"></i></div>';             message.fetchmessagelist(profile_id, message.initialmessagelisthandler('', profile_id));         }          initialmessagelisthandler: function(data, profile_id) {             $('.messages-list .message-loader profile'+ profile_id).remove();             $('.messages-list profile'+ profile_id).html(message.getmessagelisthtml(data));             message.bindmessagelist();             $('.open-message profile'+ profile_id).first().click();         },          fetchmessagelist: function(query, responsehandler) {             $.ajax({                 url: '/app/messages/fetch/' + query,                 datatype: 'json',                 method: 'get'             })                 .done(function(response) {                     responsehandler(response); <--- line errors on                 })                 .fail(function(jqxhr) {                     if (jqxhr.status == 403) {                         window.location = '/';                     } else {                         responsehandler([]);                     }                 });         }, 

this after changing from:

initialmessagelist: function(profile_id) {         $('.messages-list profile'+ profile_id).html = '<div class="message-loader profile"+ profile_id><i class="fa fa-spinner fa-spin"></i></div>';         message.fetchmessagelist(profile_id, message.initialmessagelisthandler);     },      initialmessagelisthandler: function(data) {         $('.messages-list .message-loader ').remove();         $('.messages-list ').html(message.getmessagelisthtml(data));         message.bindmessagelist();         $('.open-message ').first().click();     },      fetchmessagelist: function(query, responsehandler) {         $.ajax({             url: '/app/messages/fetch/' + query,             datatype: 'json',             method: 'get'         })             .done(function(response) {                 responsehandler(response);             })             .fail(function(jqxhr) {                 if (jqxhr.status == 403) {                     window.location = '/';                 } else {                     responsehandler([]);                 }             });     }, 

you're getting error because you're not passing in function, result of called function, happens when add parentheses.

fetchmessagelist(profile_id, message.initialmessagelisthandler('', profile_id));  fetchmessagelist: function(query, responsehandler) {     responsehandler(); // error, "undefined" } 

note how you're calling initialmessagelisthandler, , has no return value, returns undefined, you're doing is

fetchmessagelist(profile_id, undefined);  fetchmessagelist: function(query, responsehandler) {     responsehandler(); // error, "undefined" } 

and should doing is

fetchmessagelist(profile_id, function() {     message.initialmessagelisthandler('', profile_id) }); 

using anonymous function wrapper, when have pass arguments that


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -