i am trying to make an ajax request from my phonegap app to servlet running on my laptop,

徘徊边缘 提交于 2020-01-16 02:55:31

问题


i am trying to make an ajax request from my phonegap app to servlet running on my laptop, its hitting server but the ajax request is always going to error part. If i will do the same request in normal browser working fine.

function cred() { 
    var username = "hisari";
    var password = "kumar";
    var ul = "ip" ;     

    $.ajax({ 
        type: "GET",
        url: ul,
        dataType: "json",
        success: function(msg, textstatus) {
            alert("success"); 
            if (msg.id != null)
            {
            } else if (msg.error_id) 
            {       
                 //Error    
                alert('Error logging in:' + msg.error_message);
            }           
        },      
        error: function(error) {            
            alert("Error connecting to the servers" + error.message);       
        }   
    }); 
}  

please give me a solution ,If possible suggest what can i use instead of servelet for login validation


回答1:


Are you using 127.0.0.1 or localhost for your IP? If so, you will need to use the actual IP of your machine when testing the app. This is because when you load the app into a device or simulator, 127.0.0.1 will resolve to the actual device or emulator itself, not your machine. (If using Android emulator, you can use 10.0.2.2 to get to your localhost on the machine, see http://developer.android.com/tools/devices/emulator.html#emulatornetworking).




回答2:


Have you added your host to whitelist in config.xml?

<access origin="http://127.0.0.1*" /> <access origin="http://*.google.com" />



来源:https://stackoverflow.com/questions/17214832/i-am-trying-to-make-an-ajax-request-from-my-phonegap-app-to-servlet-running-on-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!