0

我正在尝试为我的 PhoneGap 应用程序发出 ajax 请求。我对这些东西真的很陌生,所以我不知道我的代码有什么问题。服务器需要 facebook 令牌才能连接。当我通过终端上的“curl”执行此操作时,这是有效的,但是当我在我的 android 模拟器上运行它时,它会出现警报:“错误:内部服务器错误”Localserver 在 android 模拟器中的 10.0.2.2:9000 上正常运行。

function fun(){
  FB.getLoginStatus(function(response) {
    if (response.status == 'connected') {
        var token = response.authResponse.accessToken;
        token = '"'+token+'"';
        jQuery.ajax({
            url: "http://10.0.2.2:9000/lists/json",
            type: "GET",
            data: {"token": token},
            dataType: "json",
            success: function(result) {
                alert('Success.');
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert('ERROR: '+thrownError);
            }
        });
    } else {
    //Not logged in
    }
  });
}

任何形式的帮助将不胜感激。

4

1 回答 1

0

最后我所做的是将令牌附加到服务器的 url,如:

function fun(){
  FB.getLoginStatus(function(response) {
    if (response.status == 'connected') {
        var token = response.authResponse.accessToken;
        jQuery.ajax({
            url: "http://10.0.2.2:9000/lists/json?token="+token,
            type: "GET",
            success: function(result) {
                alert('Success.');
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert('ERROR: '+thrownError);
            }
        });
    } else {
    //Not logged in
    }
  });
}

它奏效了:)

于 2013-05-10T10:34:33.967 回答