简体   繁体   English

REST服务的Ajax调用返回状态:0

[英]Ajax call to REST service returns status:0

Ajax call from cordova android application to the REST service in the localhost, returns 从Cordova Android应用程序到localhost中REST服务的Ajax调用返回

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

I've added <access origin="*" /> to the config.xml 我已经将<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() {});
        }    
    });

I'm using GenyMotion as the Emulator. 我正在使用GenyMotion作为模拟器。

According to this answer, I created entirely a new cordova project and copied the www folder in to it. 根据答案,我创建了一个全新的cordova项目,并将www文件夹复制到其中。 Then build and run worked. 然后构建并运行。 the AJAX call works fine. AJAX调用工作正常。 There was no any changes made to the code. 没有对代码进行任何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM