2017-05-05 80 views
0

我正在使用科尔多瓦来创建一个简单的登录窗体的移动应用程序。问题是,只要我输入了错误的用户名和密码,我就可以从服务器获取XML中的INVALID INFORMATION的响应。 但是,当我输入有效的用户名和密码,我得到登录控制台作为XHR失败加载:POSTXHR失败加载:在科尔多瓦的POST

任何人都可以帮助我解决这个问题吗?

$(document).ready(function(){ 
    $("#login").click(function(){ 
     $.ajax({ 
      url: "http://remoteServerIP/login.do", 
      data:{ 
       password:$('#pass').val(), 
       method:"login", 
       userName:$('#uname').val(), 
       cType:"LOGIN" 
       }, 
      type:'post', 
      dataType: 'xml', 
      async: true, 
      contentType:"application/x-www-form-urlencoded", 
      success: function(result){ 


        alert("Data: "+result.data); 

      }, 
      error: function(xhr, ajaxOptions, thrownError){ 

      alert("msg: "+thrownError.message+" , status: "+xhr.status); 
      } 
    }); 
    }); 
}); 

config.xml文件: -

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.MyApp.App" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <preference name = "SplashScreen" value = "screen" /> 
    <preference name = "SplashScreenDelay" value = "4000" /> 
    <preference name = "SplashMaintainAspectRatio" value = "true" /> 
    <preference name="Orientation" value="portrait"/> 


    <name>DikshaTouch</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="index.html" /> 
    <plugin name="cordova-plugin-whitelist" spec="1" /> 
    <!-- <access origin="*" /> --> 
    <access origin="http://remoteServerIP" subdomain="true" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="https://*/*" /> 
    <allow-intent href="tel:*" /> 
    <allow-intent href="sms:*" /> 
    <allow-intent href="mailto:*" /> 
    <allow-intent href="geo:*" /> 
    <platform name="android"> 
     <allow-intent href="market:*" /> 
     <icon src="www/img/icon.png" density="ldpi" /> 
     <icon src="www/img/icon.png" density="mdpi" /> 
     <icon src="www/img/icon.png" density="hdpi" /> 
     <icon src="www/img/icon.png" density="xhdpi" /> 
     <icon src="www/img/icon.png" density="xxhdpi" /> 
     <icon src="www/img/icon.png" density="xxxhdpi" /> 
    </platform> 
    <platform name="ios"> 
     <allow-intent href="itms:*" /> 
     <allow-intent href="itms-apps:*" /> 
    </platform> 
</widget>` 
+0

任何控制台错误404,500? – madalinivascu

+0

不,只有当我输入有效数据时XHR加载失败。感谢您的回复 – AkshayPalekar

+0

我没有在您的ajax请求中看到任何console.log,所以这个错误是来自另一个代码 – madalinivascu

回答

0

我只是解决了这个问题。 问题是我正在使异步调用这就是为什么它的调试日志为XHR加载失败:POST当我发送vaild数据到服务器。 我只是改变异步:真异步:假

这是我改变代码: -

$(document).ready(function(){ 
    $("#login").click(function(){ 
     $.ajax({ 
      url: "http://remoteServerIP/login.do", 
      data:{ 
       password:$('#pass').val(), 
       method:"login", 
       userName:$('#uname').val(), 
       cType:"LOGIN" 
       }, 
      type:'post', 
      dataType: 'xml', 
      async: false, 
      contentType:"application/x-www-form-urlencoded", 
      success: function(result){ 


        alert("Data: "+result.data); 

      }, 
      error: function(xhr, ajaxOptions, thrownError){ 

      alert("msg: "+thrownError.message+" , status: "+xhr.status); 
      } 
    }); 
    }); 
}); 

现在我从服务器获取所需要的反应..

+0

async false是打败AJAX的用意基本上 – Gandhi

+0

雅这是弃用,但我得到的响应从服务器 – AkshayPalekar