Jquery Asynchronous call return undefined value

I have gone through many topics for jquery asynchronous AJAX requests. Here is my code.




funciton ajaxCall(path, method, params, obj, alerter) {

var resp = '';

$.ajax({

    url: path,

    type: method,

    data: params,

    async: false,

    beforeSend: function() {

        $('.black_overlay').show();

    },

    success: function(data){

        console.log(data);

        resp = callbackFunction(data, obj);

        if(alerter==0){

            if(obj==null) {

                resp=data;

            } else {

                obj.innerHTML=data;

            }

        } else {

            alert(data);

        }

    },

    error : function(error) {

        console.log(error);

    },

    complete: function() {

        removeOverlay();

    },

    dataType: "html"

});


return resp;

}

The problem is, when I use asyn is false, then I get the proper value of resp. But beforeSend doesn’t work.

In case, I put async is true, then I beforeSend work properly, but the resp value will not return properly, Its always blank.

Is there any way here where I can get solve both the problems, I would get beforeSend function and resp value both.

Thanks

Maybe your response isn’t set before you try to use it. You must give more details.