Error: $ .getJson is not a function at HTMLDocument

0

I have a .json

file
{
        "post 1"[
            {
                "folio":"1",
                "img":"imagen",
                "titulo":"bla bla bla",
                "descripcion":"nananana"
            }
        ]

        "post 2"[
            {
                "folio":"2",
                "img":"imagen2",
                "titulo":"bla bla bla2",
                "descripcion":"nananana2"
            }
        ]

        "post 3"[
            {
                "folio":"3",
                "img":"imagen3",
                "titulo":"bla bla bla3",
                "descripcion":"nananana3"
            }
        ]
}

and through Javascript I want to print your content in the view

var cad = "Los autos en el archivo JSON son:<br />";
    $.getJson('ejemplo.json',function(data){
        for(d in data){
            cad+=("<div class='pcol-sm-12 col-md-12'>" + "<div class='thumbnail'>"+ "<img src="+data[d].img+" alt='...' style='width:100px'>"+
                "<div class='caption'>"+"<h4>"+data[d].titulo+"</h4>" +"<p>" + data[d].descripcion + "...</p>"+
                "<p><a href='#' class='btn btn-success' role='button'>Ver post</a></p>"+"</div></div></div>");
        }
        $('#contenedor').html(cad);
    });

This is my index

<html>

<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="xfunciones.js"></script>
</head>

<body>
<div class="col-xs-6" runat="server" id="contenedor"></div>
</body>

</html>

But I get the following error

Uncaught TypeError: $ .getJson is not a function     at HTMLDocument. (xfunciones.js: 10)     at j (jquery.js: 2)     at Object.fireWith [as resolveWith] (jquery.js: 2)     at Function.ready (jquery.js: 2)     at HTMLDocument.J (jquery.js: 2)

    
asked by Ernesto Emmanuel Yah Lopez 19.06.2017 в 18:38
source

2 answers

1

I would do it in the "traditional" way with Ajax:

$.ajax({
    url:'ejemplo.json',
    dataType:'json',
    success:function(data){
        for(d in data){
            cad+=("<div class='pcol-sm-12 col-md-12'>" + "<div class='thumbnail'>"+ "<img src="+data[d].img+" alt='...' style='width:100px'>"+
                  "<div class='caption'>"+"<h4>"+data[d].titulo+"</h4>" +"<p>" + data[d].descripcion + "...</p>"+
                  "<p><a href='#' class='btn btn-success' role='button'>Ver post</a></p>"+"</div></div></div>");
        }
        $('#contenedor').html(cad);
    }
});
    
answered by 19.06.2017 / 23:10
source
1

From the jQuery documentation:

  

jQuery.getJSON (url [ data] [ success])   Returns: jqXHR   Description: Load JSON-encoded data from the server using HTTP GET   request.

Look for the name that is capitalized.

    
answered by 19.06.2017 в 19:19