Uncaught TypeError: jQuery(...).data(...) is not a function


一、背景:

一直運行正確的一個ajax表單提交頁面,今天報以下這個錯誤:

 

二、問題分析:

一般出現“Uncaught TypeError”這類型的錯誤,有如下4個原因:

1:引入的js里面undefined未定義該函數

這種情況一般檢查一下是否有改函數即可。一般更換新版本的js之后可能老版本的js方法就沒有了。這個時候可以手動地把老版本的js方法加到新的版本,或者更改方法。

比如遇到過 handleError is not a function 這種情況就是這個原因。如果在jquery高級版本中將這個函數添加上 ,問題解決。

; (function ($) {

            jQuery.extend({

                handleError: function (s, xhr, status, e) {

                    if (s.error) {

                        s.error.call(s.context || s, xhr, status, e);

                    }

                    if (s.global) {

                        (s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);

                    }

                },

                httpData: function (xhr, type, s) {

                    var ct = xhr.getResponseHeader("content-type"),

            xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,

            data = xml ? xhr.responseXML : xhr.responseText;

                    if (xml && data.documentElement.tagName == "parsererror")

                        throw "parsererror";

                    if (s && s.dataFilter)

                        data = s.dataFilter(data, type);

                    if (typeof data === "string") {

                        if (type == "script")

                            jQuery.globalEval(data);

                        if (type == "json")

                            data = window["eval"]("(" + data + ")");

                    }

                    return data;

                }

            });[/code]
View Code

 

2:您的js文件引入路徑錯誤了。

這個比較常見,檢查引入路徑是否正確即可。

3:您引入的js文件與別的js文件有沖突

這個時候就需要一個個的注釋掉js文件來排查。

4:您引入的js文件順序不對,也存在沖突,你就要調整一下引入順序即可,或刪除掉沖突的js文件,這是小編遇到的這種情況!

5、缺少返回的json數據

三、問題解決:

我的問題的原因屬於第4種情況。在出問題所在的頁面的模板頁(master)里面引用的 jquery.form.js 這個文件和H-ui.min.js、H-ui.admin.js 沖突了。

采用的方法是把jquery.form.js 引用放到H-ui.min.js、H-ui.admin.js這兩個前面

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM