未处理的类型错误与AJAX处理表格

问题描述:

我在我的网站上有一个简单的联系表单,我希望使用AJAX/PHP发送数据。未处理的类型错误与AJAX处理表格

当我点击提交按钮,我得到的错误:

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) - 也许这跟它有关系?

任何帮助将不胜感激。

+0

问题似乎是在jquery验证插件不在发布的代码中。 – Jai

+0

@JAI道歉 - 这里是供参考https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.js – michaelmcgurk

您使用精简版的jquery,它没有jQuery.ajaxPrefilter,但它是Jquery验证所必需的。所以使用cdn

+0

哇 - 太神奇了!就是这样。我会整天待在那里。谢谢你,先生! – michaelmcgurk