2011-04-11 212 views
1

以下是我的代碼。evalJSON不是函數

$("document").ready(function() { 
    var dataName = new Array(); 
    $.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) { 
     var JSONcustomers = $.evalJSON(responseText); 
     var total = JSONcustomers["arrayObj1"].length; 
     var index = 0; 
    }); 

雖然我得到的響應文本。但它無法將其轉換爲json。 給出以下錯誤。

$.evalJSON is not a function.

上午將所有必要的庫吧。 jquery-json.js 和jquery.js

任何想法,可能是什麼問題?

回答

0

謝謝大家!

實際上,由於其他一些內部腳本問題,jquery-json插件文件雖然顯示在DOM中加載但不能被調用方法識別。

所以我用$ .getScript,現在我的代碼如下所示

$.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) { 
$.getScript("<%=request.getContextPath()%>/web/include/js/jquery.json-2.2.min.js", 
    var JSONcustomers = $.evalJSON(responseText); 
    var total = JSONcustomers["arrayObj1"].length; 
    var index = 0; 
}); 
}); 

而且,這解決了我的問題! :)

3

這是$.parseJSON

...更多文本手動satisify 30字符限制

0

我認爲這是$.parseJSON

如果你想使用evalJSON,這裏的插件:http://code.google.com/p/jquery-json/

+0

上午使用相同的插件...仍然收到相同的錯誤 – Manu 2011-04-11 09:30:41

+0

您嘗試這第一個'$ .get('<%= request.getContextPath()%>/empBox/ajaxToGetCodes.do',function(responseText ){ alert(responseText); });'檢查返回的數據是否是有效格式,或者是否返回。 ^^ – 2011-04-11 09:43:56