2016-03-03 96 views
0

我正在開發一個手機應用程序,我有一個form註冊新用戶。在broswer(chrome和firefox)中,當填寫正確的 時,表單工作正常,如果出現錯誤則顯示錯誤。我有一個alert('work!');在函數的開始檢查是否被調用,在瀏覽器中警報出現,但在應用程序編號。可以是什麼? Ps:我已經有<access origin="">到我的網站,那裏的表單的php文件是。表單提交不要調用阿賈克斯函數phonegap

編輯:

形式:

<form id="cadastro" method="post"> 

       <input type="text" style="height:30px;margin-bottom:10px;margin-top:10px;font-size:18px" name="nome" id="textinput-2" placeholder="Nome" required> 
       <input type="text" style="height:30px;margin-bottom:10px;font-size:18px" name="email" id="textinput-1" placeholder="Email" required> 
       <div id="email_erro"></div> 

       <input type="password" style="height:30px;margin-bottom:10px;font-size:18px" name="senha" id="password" placeholder="Senha" autocomplete="off" required> 
       <input type="password" style="height:30px;margin-bottom:10px;font-size:18px" name="repetir_senha" id="re_password" placeholder="Repetir senha" autocomplete="off"> 
       <div id="senha_erro"></div> 
       <fieldset data-role="controlgroup" style="margin-left:5%" data-type="horizontal" data-mini="true"> 
                <input type="radio" name="sexo" id="radio-choice-c" value="m" checked="checked" required> 
                <label for="radio-choice-c">Masculino</label> 
                <input type="radio" name="sexo" id="radio-choice-d" value="f" required> 
                <label for="radio-choice-d">Feminino</label> 
       </fieldset>      
       <div style="margin-left:3.5%;margin-right:4%;"> 
        <input type="checkbox" name="newsletter" id="checkbox-mini-0" value="1" data-mini="true"> 
            <label for="checkbox-mini-0">Quero receber as ofertas e novidades</label> 
        <input type="checkbox" name="termo" id="checkbox-mini-1" data-mini="true" required> 
            <label for="checkbox-mini-1">Aceito os Termos de Uso e Política de privacidade</label> 
        <button type="submit" class="ui-btn ui-shadow ui-corner-all" id="termo" style="float:none;margin-left:2%">Criar conta</button> 
       </div> 
      </form> 

功能:

<script> 
     alert('entrou no script'); 
     $('#cadastro').submit(function(){ 
      var valor = $('#cadastro').serialize(); 


    $.ajax({ 
    type: 'POST', 
    url: 'cadastro', 
    dataType: "json", 
    data: valor 

    }).success(function(response){ 
     alert('retornou função'); 
     if (response.sucesso) { 

      window.localStorage["email"] = response.dados.email; 
      window.localStorage["nome"] = response.dados.nome;        
      window.localStorage["sexo"] = response.dados.sexo;        
      window.localStorage["id"] = response.dados.id; 
      //window.localStorage["UID"] = data.uid; 
      window.location = "logado.html"; 
     } else { 
      alert("Verifique seus dados"); 

      $('#email_erro').html(response.erro_email); 
      $('#senha_erro').html(response.erro_repetir_senha); 

      //window.location("main.html"); 
      } 

    }); 
    return false; 
    }); 

    </script> 
+0

我們可以看到相關的代碼嗎? – andre3wap

+0

當然,我編輯了我的帖子。 –

+0

你是否包含cordova javascript文件? - Tricky12

回答

0

我相信,你的問題是因爲你運行你的JavaScript的PhoneGap框架加載之前。嘗試使用下面的事件監聽器,然後將您的JavaScript放在相應的函數中。

document.addEventListener("deviceReady", deviceReady, false); 

function deviceReady() { 
    // PhoneGap has loaded - your code goes here 
} 
+0

我試過了,但仍然不工作! :/ –