簡體   English   中英

另一個ajax調用的成功函數中的jQuery ajax調用不起作用並且無法正確告知錯誤類型

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

我正在嘗試在另一個ajax調用成功的范圍內進行ajax調用。 這可以在localhost上正常運行,但不能在服務器上運行。

這就是我在做什么。

        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);                                      },
                                });

                        }
                          });

               });

現在,當我點擊button.The第一ajax調用(parent)工作正常,並返回我InsertFriends從PHP的答案script.Now存在的,如果條件Ajax請求InsertFriends不能正常工作和xhr.responseText為空字符串。 現在,我不知道為什么它無法正常工作。 為簡單起見,我只是在服務器端腳本上回顯了abc ,但我不知道這有什么問題。

我在Chrome Network Tab遇到以下錯誤。

在此處輸入圖片說明

那么為什么它不起作用呢?

我只是將請求類型從POST更改為GET ,並且有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM