【问题标题】:"Internal Server Error" with jQuery.ajax using phoneGap使用 phoneGap 的 jQuery.ajax 的“内部服务器错误”
【发布时间】:2013-03-13 12:09:10
【问题描述】:

我正在尝试为我的 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
    }
  });
}

我们将不胜感激。

【问题讨论】:

  • AJAX 响应中显示什么错误?
  • 你能检查令牌值是否正确吗?
  • @KD 我该如何检查?
  • @Ateszki 是的,我检查了令牌值,它似乎是正确的。
  • 如果您将浏览器指向10.0.2.2:9000/lists/json?token=validtokenvalue,您会得到什么?

标签: android jquery ajax json cordova


【解决方案1】:

最后我所做的是将令牌附加到服务器的 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
    }
  });
}

它成功了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2016-06-16
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2011-07-28
    相关资源
    最近更新 更多