Resume a #div via PHP jo Ajax file

Asked

Viewed 36 times

0

My problem is, I have a table that displays the information you have in the database registered information 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 returns success .done() in ajax I call the editaagenda.php to update the hmtl table with the updated information need to display the list the data in the index without giving reflesh on the page.

And the only way that came to mind was after insertion take the file with the $.get and play on div . read_content of the index instead of the other to update 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 for it to return only the part of the code in the file editaagenda.php where you have div with id="read_content", but this way I did it is returning all page instead of only Div with id="read_content".

  • 1

    Why not modify PHP to only return what you need? This will decrease the payload of your communication and make the data transmitted faster between client and server.

  • I edited the question better, to better understand what I am doing. And see if really this is the right way.

1 answer

2

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

However, in order not to need it, 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());
});
  • Did not return the expected result. I will test here to create a new file only with the required information. As the friend suggested above to see.

Browser other questions tagged

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