Styles do not apply to elements coming via AJAX

Asked

Viewed 28 times

0

I am mounting a page that is inserted 2 values. These values go to a page .php via AJAX and then the page returns all records from the database.

Function that registers the data:

function adiciona(){

                    var os = $('#icon_telephone').val();;
                    var descricao = $('#icon_prefix').val();;


                    $.ajax({
                        type: 'POST',
                        url: 'adiciona.php',
            dataType : 'html',
                        data: {descricao: descricao, os:os},
                        success: function(data) {
                            $("#carrega").show();
                            $("#carrega").hide();
                            console.log(data);
              exibe();
                        },
                        error: function(xhr, desc, err){
                             console.log(xhr);
                             console.log(desc);
                             console.log(err);
                        $('#notification-bar').text("Details: " + desc + "\nError:" + err);
                        }
                    });
                }

Function retrieving the data:

  function exibe(){
    $.ajax({
      type:'POST',
      dataType : 'html',
      url: 'exibe.php',
      success: function(data2){
         console.log("dados fun 2"+data2);
         $('#tabeladados').text(data2);
    //     $('#tabeladados').off();
          //     $('#tabeladados').text(data2);
        //  $("#tabeladados").on('load', 'button.actionButton', exibe());
      },
      error: function(xhr, desc, err){
         console.log(xhr);
         console.log(desc);
         console.log(err);
          $('#notification-bar').text("Details: " + desc + "\nError:" + err);
      }
    });


  }

Problem:

The exit is normal. All the data I need is returned, but the css style of the page is not applied to these returned elements, as the example below: inserir a descrição da imagem aqui

1 answer

2


Change:

$('#tabeladados').text(data2);

For:

$('#tabeladados').html(data2);

When using the method text(), means that the element text will be exactly the one passed by the parameter, even if it is a language like HTML.

Already the html() is proper to receive a string parameter in html, so it will be read as code and will be implemented on the page, as well as the include or require php.

And make sure that the page that receives this data has the same style files so that the table classes are read.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.