[英]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. 我正在尝试在另一个ajax调用成功的范围内进行ajax调用。 This is working perfectly in
localhost
but not on the server. 这可以在
localhost
上正常运行,但不能在服务器上运行。
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. 现在,当我点击button.The第一ajax调用
(parent)
工作正常,并返回我InsertFriends
从PHP的答案script.Now存在的,如果条件Ajax请求InsertFriends
不能正常工作和xhr.responseText
为空字符串。 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. 为简单起见,我只是在服务器端脚本上回显了
abc
,但我不知道这有什么问题。
I get the following error in the Chrome Network Tab
. 我在
Chrome Network Tab
遇到以下错误。
So why it is not working ? 那么为什么它不起作用呢?
我只是将请求类型从POST
更改为GET
,并且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.