虽然JQuery已加载,但未定义JQuery

时间:2015-04-15 13:10:26

标签: jquery

虽然jQuery已加载且$正在运行,但未定义jQuery。我在使用JQuery.parseJSON时遇到此错误。

  

未捕获的ReferenceError:`JQuery未定义

的index.php:

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>comment box</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="comment_insert.js"></script>
    <script type="text/javascript" src="script.js"></script>
    <link href="layout.css" rel="stylesheet"/> 
</head>

当我使用jquery.parsejson时,我收到一个错误,即JQuery未定义

comment_insert.js

$(document).ready(function(){           
    $( '#comment-post-btn').click(function(){
        comment_post_btn_click();
    });
});

function comment_post_btn_click() {
    var _comment= $('#comment-post-text').val();
    var _userId= $('#userId').val();
    var _userName= $('#userName').val();

    if (_comment.length > 0 && _userId != null) {
        $.post("comment_insert.php", {
            task: "comment_insert",
            userId: _userId,
            comment: _comment
        }).success(function(data) {
            //task: insert html into the ul/li
            comment_insert(JQuery.parsejson(data));
            console.log("ResponseText: " + data);
        });

1 个答案:

答案 0 :(得分:3)

功能区分大小写,因此您必须使用jQuery$。此外,parseJSON()是函数,而不是parsejson()

更改此行:

comment_insert(JQuery.parsejson(data));

到这一行:

comment_insert($.parseJSON(data));

或:

comment_insert(jQuery.parseJSON(data));
相关问题