e.nodeName是未定义的jQuery(仅适用于Firefox)

时间:2015-08-10 00:59:49

标签: jquery ajax

我正在使用AJAX响应做一个基本表单,但它在FireFox中没有工作(仅);在控制台中抛出此错误:

TypeError: e.nodeName is undefined.

这是我的表单(index.php):

<div id="frmContact">
<div id="mail-status"></div>
<div>
    <label style="padding-top:20px;">Name</label>
    <span id="userName-info" class="info"></span><br/>
    <input type="text" name="userName" id="userName" class="demoInputBox">
</div>
<div>
    <label>Email</label>
    <span id="userEmail-info" class="info"></span><br/>
    <input type="text" name="userEmail" id="userEmail" class="demoInputBox">
</div>
<div>
    <label>Subject</label> 
    <span id="subject-info" class="info"></span><br/>
    <input type="text" name="subject" id="subject" class="demoInputBox">
</div>
<div>
    <label>Content</label> 
    <span id="content-info" class="info"></span><br/>
    <textarea name="content" id="content" class="demoInputBox" cols="60" rows="6"></textarea>
</div>
<div>
<button name="submit" class="btnAction" onClick="sendContact();">Send</button>
</div>

我的javascript(index.php文件的结尾):

    <script>
function sendContact() {
    var valid;  
    valid = validateContact();
    if(valid) {
        jQuery.ajax({
        url: "contact_mail.php",
        data:'userName='+$("#userName").val()+'&userEmail='+$("#userEmail").val()+'&subject='+$("#subject").val()+'&content='+$(content).val(),
        type: "POST",
        success:function(data){
        },
        error:function (){}
        });
    }
}

function validateContact() {
    var valid = true;   
    $(".demoInputBox").css('background-color','');
    $(".info").html('');

    if(!$("#userName").val()) {
        $("#userName-info").html("(required)");
        $("#userName").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#userEmail").val()) {
        $("#userEmail-info").html("(required)");
        $("#userEmail").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#userEmail").val().match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) {
        $("#userEmail-info").html("(invalid)");
        $("#userEmail").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#subject").val()) {
        $("#subject-info").html("(required)");
        $("#subject").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#content").val()) {
        $("#content-info").html("(required)");
        $("#content").css('background-color','#FFFFDF');
        valid = false;
    }

    return valid;
}

contact_mail.php是邮件php函数。

感谢帮助人们。

1 个答案:

答案 0 :(得分:2)

代码中的数据:

{'userName':$("#userName").val(),'userEmail':$("#userEmail").val(),'subjec‌t':$("#subject").val(),'content':$(content).val()}

应该在哪里

{'userName':$("#userName").val(),'userEmail':$("#userEmail").val(),'subjec‌t':$("#subject").val(),'content':$('#content').val()}

内容应为$(&#39; #content&#39;)

多数民众赞成:)