被拒绝访问财产'类型'

时间:2015-03-13 14:12:28

标签: jquery ajax forms

我有一个用jQuery处理AJAX请求的表单,我在控制台中收到错误;

  

错误:拒绝访问属性的权限'键入'

在第5行的jquery.min.js文件中,第3395行。

的jQuery

<script language="javascript">
(document).ready(function() {
    $('#emvForm').submit(function(event) {
        event.preventDefault();
        var email, nm;

        email = $('#emailfield').val;
        nm = $('#namefield').val;

        if (email != '' && nm != '') {
            $.ajax({
                type: 'post',
                url: '/ajax/enewsletter_subscribe',
                data: {
                    'email': email,
                    'name': nm,
                },
                success: function(data) {
                    $('#form-nlfm').slideUp(200).html('<h2>Thank You</h2><p class="text-center">You are now signed up to our mail list.</p>').slideDown(500);
                },
            });
        }
    });
});
</script>

HTML

<form accept-charset="utf-8" action="" id="emvForm" method="POST" name="emvForm" role="form" target="_top">
 <div class="result"></div>
 <div class="form-area col-xs-10 col-xs-offset-1" id="form-nlfm">
 <div class="form-group"><input class="form-control" id="namefield" name="name" placeholder="Your Name" size="30" type="text" value="" /></div>
 <div class="form-group"><input class="form-control" id="emailfield" maxlength="64" name="email" placeholder="Your Email Address" size="30" type="text" value="" /></div>
 <p class="text-center"><button id="nlfm-submit" class="submit button">Subscribe</button></p>
 </div>
</form>

我尝试过更改选择器,重命名变量和其他类似的东西。

1 个答案:

答案 0 :(得分:0)

你有这个:

email = $('#emailfield').val;
nm = $('#namefield').val;

应该是这样,因为jQuery的val是一个函数:

email = $('#emailfield').val();
nm = $('#namefield').val();