Javascript : callback is not a function -


i using vanilla javascript making ajax call apis.

below code calling on click of simple button:

    getuserbyuserid : function (callback){          var userid = localstorage.getitem('userid');         var userapiurl = "http://174.129.30.174:8080/users/"+userid;          var xmlhttp = micropaywall.getajaxinstance();         xmlhttp.onreadystatechange = function()          {              if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {                  var response = json.parse(xmlhttp.responsetext);                 callback(xmlhttp.responsetext);                 console.log(response);                 console.log(xmlhttp.responsetext);             }         };         xmlhttp.open("get", userapiurl, true);         xmlhttp.send(null);     } 

but "callback not function" @ line

callback(xmlhttp.responsetext);

below callback function :

getuserbyuseridcallback : function(response){            if(response != "")           {                var res = json.parse(response);               var arrappid = res.appids;               var userid = res._id;               localstorage.setitem('appid', arrappid[0]);               var appid = localstorage.getitem('appid');               micropaywall.getuseraccountdetails(userid, appid);           }       } 

please correct me making mistake.

if don't need change "callback" function can call directly:

if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {     var response = json.parse(xmlhttp.responsetext);     getuserbyuseridcallback(xmlhttp.responsetext);     console.log(response);     console.log(xmlhttp.responsetext); } 

you need pass in callback function if want different behavior when calling getuserbyuserid function.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -