2017-04-17 96 views
0

我在我的網站上有一個簡單的聯繫表單,我希望使用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

回答

1

您使用精簡版的jquery,它沒有jQuery.ajaxPrefilter,但它是Jquery驗證所必需的。所以使用cdn

+0

哇 - 太神奇了!就是這樣。我會整天待在那裏。謝謝你,先生! – michaelmcgurk