处理表单时,AJAX未捕获TypeError [英] Uncaught TypeError with AJAX when processing form

查看:94
本文介绍了处理表单时,AJAX未捕获TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个简单的联系表,希望通过AJAX/PHP发送数据.

I have a simple contact form on my website that I'm hoping to send data with using AJAX/PHP.

当我点击提交"按钮时,出现错误:

When I hit the submit button, I get the error:

Uncaught TypeError: Cannot read property 'mode' of undefined
    at Function.$.ajax (jquery.validate.js:1561)
    at submitForm (form-scripts.js:21)

第21行从下面开始:

代码:

$.ajax({
    type: "POST",
    url: "php/form-process.php",
    data: "name=" + name + "&email=" + email + "&message=" + message,
    success : function(text){
        if (text == "success"){
            formSuccess();
        } else {
            formError();
            submitMSG(false,text);
        }
    }
});

我正在使用jQuery 3.1.1( https://code .jquery.com/jquery-3.1.1.slim.min.js )-也许这与它有关?

I am using jQuery 3.1.1 (https://code.jquery.com/jquery-3.1.1.slim.min.js) - perhaps this has something to do with it?

任何帮助将不胜感激.

推荐答案

您使用的精简版jquery没有jQuery.ajaxPrefilter,但Jquery validate必需.因此,请使用此 cdn

Your using lite version of jquery which doesn't have jQuery.ajaxPrefilter but it is required by Jquery validate. So use this cdn

这篇关于处理表单时,AJAX未捕获TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆