【问题标题】:Ajax call to REST service returns status:0对 REST 服务的 Ajax 调用返回状态:0
【发布时间】:2015-07-31 21:50:29
【问题描述】:

从cordova android应用程序到localhost中的REST服务的Ajax调用,返回

{ "readyState" : 0, "responseText" : "", "statusText" : "error" }

我已将<access origin="*" /> 添加到 config.xml

    $.ajax({        
        type: "POST",    
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(dataObject),
        url: "http://10.0.3.2:8080/ServiceProject/rest/vsa-service/auth",
        success: function(result){            
            if(result.auth){ 
                window.localStorage["authentication"] = result.authCode;
                window.localStorage["authDetails"] = result.details;                                    
                $.mobile.changePage("#home");    
            }                
            else{
                navigator.notification.alert('Login failed. Try again.', function() {});                        
            }
        },
        error: function(err){
            navigator.notification.alert('Error occurred unexpectedly.' + JSON.stringify(err) , function() {});
        }    
    });

我使用 GenyMotion 作为模拟器。

【问题讨论】:

    标签: android ajax json cordova rest


    【解决方案1】:

    根据this 的回答,我创建了一个全新的cordova 项目并将www 文件夹复制到其中。然后构建并运行工作。 AJAX 调用工作正常。没有对代码进行任何更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 2013-10-28
      相关资源
      最近更新 更多