Ad

Add Response Ajax In A Div

- 1 answer

I am trying to add a response in json format to a column but I get the following error: "Uncaught TypeError: response[i].name.appendTo is not a function".

function allUsers(){
        $(".error").remove();
        $("#tabla").remove();
        $.ajax({
            type: "GET",
            url: "mylocalhost/public/api/user",
            contentType: "application/json",    
            dataType:'json',

             beforeSend: function(request) {
                    request.setRequestHeader("Authorization", localStorage.getItem("token"));
                },
            success: function(response){
                console.log(response);




for (i = 0; i < response.length; i++) {

                    $('<div class="prueba"/><br>')+(response[i].name).appendTo('#filaNombre');

                    ...
Ad

Answer

Try changing this line:

$('<div class="prueba"/><br>')+(response[i].name).appendTo('#filaNombre');

to this:

$('<div class="prueba"><br>' + response[i].name + '</div>').appendTo('#filaNombre');
Ad
source: stackoverflow.com
Ad