Yii Framework Forum: Jquery Asynchronous call return undefined value - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Jquery Asynchronous call return undefined value Rate Topic: -----

#1 User is offline   raghavAgarwal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 21-March 13
  • Location:Gurgaon

Posted 13 September 2016 - 07:05 AM

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
0

#2 User is offline   PaweĊ‚ Reja 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 04-September 16
  • Location:Poland

Posted 17 September 2016 - 08:12 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users