Retract a #div via PHP file Ajax

0

My problem is, I have a table that displays the information that has in the database the information entered in the index. And in the index you have the option to add a new record (Modal Ajax), in the file editaagenda.php has all forms (CRUD) when it returns .done() success in ajax I call editaagenda.php to update the hmtl table with updated information I need to display the data list in the index without having to reflesh the page.

And the only way I came to mind was after insert grab the file with $ .get and play in the .read_content div of the index instead of the other to upgrade without reflesh.

My code:

 $.ajax({
        url: 'add-data.php',
        cache: false,
        contentType: false,
        processData: false,
        data: dados,
        type: 'post'
    }).done(function (data) {
        $('#addfrm').modal('hide');
        $('#frm')[0].reset();
        $.get("editaagenda.php?#read_content", {}, function (data, status) {
            $(".read_content").html(data);
        });

It would be this way so that it returns only the part of the code in the file editaagenda.php where it has the div with id="read_content", but this way I did it is returning every page instead of just the Div with id="read_content".

    
asked by anonymous 19.09.2018 / 18:08

1 answer

2

You do not have the option to request only one element as it did (unless you create a server-side treaty).

However, to not need this, you can select directly from the front end, using jQuery:

$.get('editaagenda.php', function (data) {
  var $root = $(data);
  $('.read_content').html($('#read_content', $root).html());
});
    
19.09.2018 / 18:11