2017-05-05 6 views
0

간단한 로그인 양식으로 모바일 앱을 개발하는 데 cordova를 사용하고 있습니다. 문제는 잘못된 사용자 이름과 암호를 입력 할 때마다 서버에서 XML의 잘못된 정보로 응답을받을 수 있다는 것입니다. 하지만 유효한 사용자 이름과 암호를 입력하면 콘솔에 로그인 할 때 XHR로드 실패 : POST.XHR로드 실패 : POST in cordova

누구든지이 문제를 해결할 수 있습니까?

$(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

아약스 요청에 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

비동기 false는 AJAX의 목표를 근본적으로이기는 것입니다. – Gandhi

+0

예, 더 이상 사용되지 않지만 서버에서 응답을 얻고 있습니다. – AkshayPalekar