$ (...). getJSON is not a function

I am trying to develop a simple API call that returns my comments in a JSON response, but when I click on it I get an error

$(...).getJSON is not a function

My idea: when I click the Comment button (id = showarea), it immediately prints comments from this answer and text field.

I have "hardcoding" in the file for testing only.

I had this file (javascript / askme / comment.js)

function initCommentReloader() {
    $('#textarea').on('click', 'a', function() {
        $.getJSON("/controller/api/comments/comment.php", {answerid: answerid}, function(data) {
            $.each(data, function(i, comment) {
                console.log(comment);
            });
        });
    });
}

but when nothing happens, it doesn't even recognize the click, then I went to the hard drive and an error occurred. I checked that my jquery is turned on and everything seems to be properly turned on.

This is the file in which I am trying to upload comments. Can you find something wrong?

I'm sorry if this is an extreme newbie, but I have stressed it too much.

Yours faithfully

 <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">

    <title>AskMe</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">


    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

    <script>
        $( function() {
            $( "#tabs" ).tabs();
        } );
    </script>

    <!-- CSS -->
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/fonts/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/fonts/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/styles/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/styles/main.css">
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/styles/responsive.css">
    <link rel="stylesheet" type="text/css" href="{$BASE_URL}css/styles/clean-blog.min.css">

    <!-- JS -->
    <script type="text/javascript" src="{$BASE_URL}javascript/vendor/bootstrap.js"></script>
    <script type="text/javascript" src= "{$BASE_URL}javascript/Chart.js"></script>
    <script type="text/javascript" src="{$BASE_URL}javascript/main.js"></script>
    <script src="https://cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>

</head>


<div class="post-button clearfix">
                <button class="btn icon-chat" title="Add a comment on this answer"
                        type="submit" id="showarea" name="showarea" value="Show Textarea">
                    Comment</button>
                <div id="textarea">
                    {include file="comment.tpl"}
                    {include file="comment_form.tpl"}
                </div>
            </div>

<script>
    answerid = {$answer['answerid']};
    console.log();
    $("#showarea").click(function() {
        $("#showarea").getJSON("/controller/api/comments/comment.php", function (data) {
            console.log(data);
        });
    });
</script>
{HTML::script('askme/comment.js')}
+4
4

:

  $(document).on('click', '#textarea>a', function() {
        $.getJSON("/controller/api/comments/comment.php", {answerid: answerid}, function(data) {
            $.each(data, function(i, comment) {
             console.log(comment);
            });
        });
    });

  $(document).on('click', '#textarea>a', function() {
    $.getJSON( "/controller/api/comments/comment.php", {answerid: answerid})
  .done(function( data ) {
    $.each(data, function(i, comment) {
       console.log(comment);
      });
    })
  });

 $(document).on('click', '#textarea>a', function() {
  $.ajax({
  dataType: "json",
  url: "/controller/api/comments/comment.php",
  data: {answerid: answerid},
  success: success
}).done(function( data ) {
    $.each(data, function(i, comment) {
     console.log(comment);
     });
  });

});

0

,

$("#showarea").getJSON

$.getJSON
+1

, - jQuery

$.getJSON

jQuery.getJSON

$. getJSON $. ajax ( jQuery) $. getJSON Ajax , :

$.ajax({
    dataType: "json",
    url: url,
    data: data,
    success: success
});
0

, "" jQuery, ajax, .. , jQuery, ".slim", .

, , , jQuery 404 .

0

Source: https://habr.com/ru/post/1675570/


All Articles