我需要点击两次才能使用ajax提交表单

时间:2014-06-30 16:04:17

标签: javascript jquery forms

我有一个用于验证用户的表单,现在我正在测试并需要发送2次点击,我在许多论坛中阅读但无法找到问题的解决方案。

这是脚本代码:

<script>
    $(function () {
        $('#enviar').click( function() {
                   if($('#correo').val().length > 0 && $('#pwd').val().length > 0){
                       var pwd2 = MD5($('#pwd').val());

                       var myData = "correo="+$('#correo').val()+"&pwd="+pwd2;
                        $.ajax({
                            type: "POST",
                             url:"http://myurlthatisworkingfine/registro/login",
                             data: myData,
                             dataType: 'json', // Notice! JSONP <-- P (lowercase)
                             success: function(data) {
                                        alert(data.message);
                                    }
                             },
                             error:function(){
                                 alert("Error");
                             }      
                        });
                    } else {
                            alert('Por favor, rellena los dos campos');
                            }          
                    return false;
          });
    }); 

</script>

表格:

<form id="check-user" data-ajax="false">
            <fieldset>
                <div data-role="fieldcontain">
                    <label> Usuario </label>
                    <input type="text" id="correo" name="correo">
                </div>
                <div data-role="fieldcontain">
                    <label> Contrase&ntilde;a </label>
                    <input type="password" id="pwd" name="pwd" >
                </div>
                <input type="submit" data-role="button" value="Acceder" name="enviar" id="enviar">

                <a href="pasword.html" data-role="button" data-icon="home" data-theme="a">He olvidado mi contrase&ntilde;a</a>
            </fieldset>
        </form>

所有工作都非常好,这是提交的唯一问题,我最后需要2次发送表格。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

  <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">     
                <input type="radio" name="" id="inputID1" value=""  />
                <label for="inputID1">LabelText...</label>

                <input type="radio" name="" id="inputID2" value=""  />
                <label for="inputIDd">LabelText2...</label>

                <!-- .. more inputs maybe ..-->
       </fieldset>
   </div> 

我很确定你的div data-role =&#34; fieldcontain&#34; &安培;&安培; fieldset data-role =&#34; controlgroup&#34;是错误的方式。尝试按照上面的示例中所示执行html部分。所以不要给每个输入一个数据角色=&#34; fieldcontain&#34;本身..

Jquery mobile在获取输入点击特别是单选按钮方面存在一些问题。但如果你用这种方式标记,它应该可以正常工作。 (它在我的项目上做了)

希望有帮助...

相关问题