首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表单提交不要调用ajax函数phonegap

表单提交不要调用ajax函数phonegap
EN

Stack Overflow用户
提问于 2016-03-03 18:25:43
回答 1查看 105关注 0票数 0

我正在用phonegap开发一个移动应用程序,我有一个form来注册新用户。在broswer(chrome和firefox)中,如果填入正确,表单工作正常,如果出现错误,则显示错误。我在函数的开头有一个alert('work!');来检查是否被调用,在浏览器中警报会出现,但是在应用程序no中。什么可以是?Ps:我已经有<access origin="">到我的网站,那里的php文件的形式是。

编辑:

表格:

代码语言:javascript
复制
<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>

职能:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2016-03-03 18:56:27

我认为您的问题是因为您正在phonegap框架加载之前运行javascript。尝试使用下面的事件侦听器,然后将您的javascript放在相应的函数中。

代码语言:javascript
复制
document.addEventListener("deviceReady", deviceReady, false);

function deviceReady() {
    // PhoneGap has loaded - your code goes here
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35780064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档