Problems printing a jx ajax

0

Now I have a Jquery function

$("#btn").click(function() {

         $.ajax({
            type:"POST",
            url:"cUrl.php",
            datatype:"JSON",
            success: function(data){

                 $('#contenedor').html("<div class='pcol-sm-12 col-md-12'>"+"<div class='thumbnail'>"+ "<img src='logo.png' alt='...' style='width:100px'>"
                        +"<div class='caption'>"+ "<h4>"+data.Error+"</h4>" + "<p>" + data+ "...</p>" +
                       "<p><a href='#' class='btn btn-success' role='button'>Ver post</a></p>"+"</div></div></div>");


            }
        });

   }); 

and return the next Json

"{\"$id\":\"1\",\"Error\":0,\"Usuario\":\"jesus\"}" ...

But when printing it

 $('#contenedor').html("<div class='pcol-sm-12 col-md-12'>"+"<div class='thumbnail'>"+ "<img src='logo.png' alt='...' style='width:100px'>"
                            +"<div class='caption'>"+ "<h4>"+data.Error+"</h4>" + "<p>" + data+ "...</p>" +
                           "<p><a href='#' class='btn btn-success' role='button'>Ver post</a></p>"+"</div></div></div>");

Mark me Undefine . Some solution

    
asked by Ernesto Emmanuel Yah Lopez 19.06.2017 в 23:41
source

2 answers

1

You should try parsing your JSON:

var datos = JSON.parse(data);

so you can access its elements.

datos.Error  
datos.Usuario
    
answered by 20.06.2017 / 00:13
source
1

You are trying to show data, and you should access the elements:

... "<p>" + data.id + "</p>" ...

Or use JSON.stringify (data) to convert it to a text string.

    
answered by 20.06.2017 в 00:12