2014-02-07 3 views
0
<form method="POST" class="userform" id="loginForm"> 
    <div data-role="content"> 
     <h2> Login:</h2> 
     <div data-role="fieldcontain"> 
      <input name="email" placeholder="put your name" type="email" data-mini="true"> 
     </div> 
     <div data-role="fieldcontain"> 
      <input name="password" placeholder="enter your password" type="password" data-mini="true"> 
     </div> 
     <input type="submit" data-theme="a" value="submit" id="submitButton"> 
     <h5 align="center"> 
      <a href="user_rbooks.html"> Forget password? </a> 
     </h5> 
     </div> 
     </form> 

이 내 login.js입니다위한 인증은

$.fn.serializeObject = function() 
{ 
    var o = {}; 
    var a = this.serializeArray(); 
    $.each(a, function() { 
     if (o[this.name]) { 
      if (!o[this.name].push) { 
       o[this.name] = [o[this.name]]; 
      } 
      o[this.name].push(this.value || ''); 
     } else { 
      o[this.name] = this.value || ''; 
     } 
    }); 
    return o; 
}; 

var $bro = $('#loginForm'); 

$('#submitButton').click(function(e) { 
     //console.log("submit button has been clicked"); 
     e.preventDefault(); //cancel form submit 

     var jsObj = $bro.serializeObject() 
      , ajaxObj = {}; 

     //console.log(jsObj); 

     ajaxObj = { 
      type: "POST", 
      url: "http://192.168.0.100:8080/AdvancedLibrarySystem/api/v1/login", 
      data: JSON.stringify(jsObj), 
      contentType:"application/json", 
      error: function(jqXHR, textStatus, errorThrown) { 
       console.log("Error " + jqXHR.getAllResponseHeaders() + " " + errorThrown); 
      }, 
      success: function(data) { 
       console.log(data); 
       if(data[0].status == '200') { 
        alert("Welcome!!!") 
        $('#div_ajaxResponse').text(data[0]); 
        $.mobile.changePage('home.html'); 
       } 
       else{ 
       alert("Incorret Username or Password!!!") 
       } 

      }, 
      complete: function(XMLHttpRequest) { 
       //console.log(XMLHttpRequest.getAllResponseHeaders()); 
      }, 
      dataType: "json" //request JSON 
     }; 

     $.ajax(ajaxObj); 
    }); 

내가 크롬에서 해당 코드를 실행하기 위해 노력하고있어 만약 내가 아약스를 통해 폰갭에위한 인증을 사용하려고하지만거야 콘솔 잘 작동하지만 내 phonegap 응용 프로그램에서 서버에서 응답을주고있어 그것을 사용하는 경우 ... 누구든지 나를 도울 수 있습니다 ...

답변

0

나는 당신이 '응답을 제공하지 않음을 의미하는 것이 확실하지 않습니다. 서버에서 '하지만, 체크 아웃 할 가치가있는 한 가지는 phonegap 프로젝트의 config.xml에있는 도메인 간 옵션입니다. 액세스 할 수있는 도메인을 지정하는 "액세스"태그가 있어야합니다. "*"로 설정하고 다시 시도하십시오.

+0

내 "액세스"태그 나는 그것을 의미하는 모든 도메인에 액세스하도록 설정