0

This is my script:

var ckit = (function($){
var data = [{
      "option": "com_easysocial",
      "userId": localStorage.getItem("ckuser"),
      "layout": "getSample",
      "view": "conversations",
      "format": "json",
      "limit": 1
    }];

var Data = 'default';
function ajaxCall(opt, arg){

    // for(var i=0; i< opt.length; i++){
        var opt = jQuery.extend({}, data[0], opt[0]);
        this.Data = opt['layout'];
        var str = opt['layout'].replace("get", "");
        str = str.toLowerCase();
        token = window.es.token;
        opt[token] = "1";
        var res;
        jQuery.ajax({

           method: "POST",
           url: localStorage.getItem("root")+"/index.php",
           "data": opt,
           error: function() {
             alert('error');
           },  
           success: function(result) {
            console.debug(result);
           var data = result.data[str];
           return data;

           }//end success
       });//end ajax


  // }
}
     return {
        open: function(){
            $('[data-ckit-full]').removeClass("is-hidden");
            $('[data-ckit-compact]').addClass("is-hidden");
            $('body').addClass("disable-scrolling");
           // $("html").css({"height": "100%", "overflow": "hidden"});
            $("body").css({"position": "relative"});
        },
        render: function(opt){
                if(typeof opt === 'object')
                {
                    var list = {
                       data : [opt]
                    }

                    var display = ajaxCall.bind (null, ajaxCall.call (list, list.data));
                     console.debug(display);


                }
        }

         };//end return
    })(jQuery);

and this is what I see in the console in firefox

bound ajaxCall()//for  console.debug(display);

Object { data={...}}//console.debug(result);

All I'm trying to do is, to pass object from ajax success function to the calling display variable. But it's not returning the object.Also the binding call to the ajax call executed first before ajax.

WHat's the proper way of doing this?

112233
  • 2,406
  • 3
  • 38
  • 88
  • asynchronous calls don't return to caller method – gurvinder372 Jul 25 '16 at 14:10
  • Your title is the definition of what asynchronous code is used for. You need to pass a callback function to execute after the AJAX request completes. See the question I marked as duplicate for more details – Rory McCrossan Jul 25 '16 at 14:11

0 Answers0