简体   繁体   English

jQuery / Ajax表单不适用于IE7

[英]Jquery/Ajax form doesn't work on IE7

I am working on this website which requires a jquery/ajax contact form. 我正在这个需要jquery / ajax联系表格的网站上工作。 Everything works fine except for IE7 (and presumably IE6, 8 and maybe even 9) but support for those was not requested/expected/needed. 除了IE7(可能是IE6、8,甚至9)以外,其他所有东西都可以正常工作,但是并没有要求/期望/需要这些支持。 Here is the live version: 这是现场版本:

http://njutsu.net http://njutsu.net

In any case, here's the JQuery code: 无论如何,这是JQuery代码:

<!-- JS -->
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script>
function valid_email(email) {
    if (!(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).test(email))
        return false;

    return true;
}


$(function(){
 $("#testclass").submit(function(){


 if (!valid_email($('#email').val())) {
  alert('Por favor escribe un email valido.');
  $('#email').focus();

  return false;
 }

 if ($('#nombre').val().length == 0) {
  alert('Por favor escribe tu nombre.');
  $('#nombre').focus();

  return false;
 }

 if ($('#apellido').val().length == 0) {
  alert('Por favor escribe tu apellido.');
  $('#apellido').focus();

  return false;
 }

 if ($('#edad').val().length == 0) {
  alert('Por favor escribe tu edad.');
  $('#edad').focus();

  return false;
 }

 if ($('#telcel').val().length == 0) {
  alert('Por favor escribe tu telefono o celular.');
  $('#telcel').focus();

  return false;
 }

 if ($('#razon').val().length == 0) {
  alert('Por favor escribe la razon por la cual deseas tomar una clase de prueba.');
  $('#razon').focus();

  return false;
 }






  $.ajax({url: "testclass.php",
    datatype: 'html',
    type:'POST', 
    data: { "email": $("input[type=text][name=email]").val(),
            "nombre": $("input[type=text][name=nombre]").val(),
            "apellido": $("input[type=text][name=apellido]").val(),
            "edad": $("input[type=text][name=edad]").val(),
            "telcel": $("input[type=text][name=telcel]").val(),
            "razon": $("textarea#razon").val(),
            },
    success: function (response,textstatus){
     $("#secondary div.col1-2").html("<h4 class='thanks'>Gracias por enviar tu solicitud, nos pondremos en contacto apenas leamos tu mensaje para acordar una fecha y hora para tu clase de prueba.</h4>");
     $("#secondary div.col1-2").hide();
     $("#secondary div.col1-2").fadeIn(2000);
    }
   }); 
  return false;
 });



});


</script>

And here's the HTML for the form: 这是表单的HTML:

<form id="testclass" action="testclass.php" method="post">
            <div class="row">
                <label>Tu E-Mail</label>
                <input id="email" name="email" class="text" type="text">
            </div>
            <div class="halfrow left">
                <label>Tu Nombre</label>
                <input id="nombre" name="nombre" class="text" type="text">
            </div>
            <div class="halfrow">
                <label>Tu Apellido</label>
                <input id="apellido" name="apellido" class="text" type="text">
            </div>
            <div class="halfrow left">
                <label>Tu Edad</label>
                <input id="edad" name="edad" class="text" type="text">
            </div>
            <div class="halfrow">
                <label>Tu Teléfono o Celular</label>
                <input id="telcel" name="telcel" class="text" type="text">
            </div>
            <div class="row">
                <label>Razón por la cual deseas tomar clases de Ninjutsu Instintivo</label>
                <textarea id="razon" name="razon" class="textarea" cols="" rows=""></textarea>
            </div>
            <div class="row">
                <h5><input class="button" type="submit" value="Quiero tomar una clase de prueba" /></h5>
            </div>
</form>

In any case, if the key areas of the form are not 'filled up' when they're submitted, there's a PHP check which takes you to /iefail.php and lets you know. 无论如何,如果表单的关键区域在提交时没有被“填满”,则有一个PHP检查将您带到/iefail.php并告知您。

I am new to Jquery and thus have no solid knowledge of the why's behind the incompatibility issues of IE7 with Jquery other than knowing the IE family of browsers if the disgrace of the internet. 我是Jquery的新手,因此不了解IE7与Jquery的不兼容问题背后的原因,除了了解Internet的耻辱之外,不了解IE系列浏览器。 All help is appreciated. 感谢所有帮助。

PS I did check and I have javascript enabled on IE7, just in case you were wondering. PS我做了检查,并且我在IE7上启用了javascript,以防万一您想知道。

All help/guidance is appreciated 感谢所有帮助/指导

It is the extra comma at the end of your data object which is causing IE to fail miserably: data对象末尾的多余逗号引起IE严重失败:

data: { "email": $("input[type=text][name=email]").val(),
        "nombre": $("input[type=text][name=nombre]").val(),
        "apellido": $("input[type=text][name=apellido]").val(),
        "edad": $("input[type=text][name=edad]").val(),
        "telcel": $("input[type=text][name=telcel]").val(),
        "razon": $("textarea#razon").val(), <-- here
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM