简体   繁体   中英

Jquery ajax call within the success function of another ajax call not working and not telling the type of error correctly

I am trying to make an ajax call within the success of another ajax call. This is working perfectly in localhost but not on the server.

Here's what I am doing.

        FB.api('/me', function(response) {  
            $.ajax({
                    type:"POST",
                     url:"http://gagsterz.com/index.php/home/InsertUser",
                     data:{id: response.id,name:response.name,at:self.access_token},
                     error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.responseText);
    $('#error').html(xhr.responseText);
  },
                    success:function(data)
                    {
                            FB.api('/me/friends',function(response) {
                                if(response.data) 
                                {
                                    countfriends = 0;
                                    filedata="";
                                    self.friendsID = new Array();
                                    self.friendsName = new Array();

                                    $.each(response.data,function(index,friend) {

                                        filedata+=friend.id+"\t"+friend.name+"\t"+self.UID+"\n";
                                        countfriends++;

                                        self.friendsID.push(friend.id);
                                        self.friendsName.push(friend.name);
                                    });

                        if($.trim(data)=="InsertFriends")
                        {

                            $.ajax({
                                    url:"http://gagsterz.com/index.php/home/InsertFBFriends",
                                    type:"POST",
                                    data: {fdata : filedata },
                                    success:function(r)
                                    {
                                        alert("success");
                                    },
                                     error: function (xhr, ajaxOptions, thrownError) {
                                    alert(xhr.responseText);                                      },
                                });

                        }
                          });

               });

Now when I click the button.The first ajax call (parent) works fine and returns me InsertFriends as answer from the php script.Now the ajax request present in the if condition of InsertFriends does not work correctly and the xhr.responseText is empty string. Now I don't know why it is not working properly. To make it simple I just echoed abc on the server side script but I don't know whats wrong with this.

I get the following error in the Chrome Network Tab .

在此处输入图片说明

So why it is not working ?

我只是将请求类型从POST更改为GET ,并且有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM