JQuery: Can content downloaded via ajax update the DOM?

I have a list of posts uploaded to my page using ajax:

var fm = <?php echo $from_user ;?>;

$("#microblogposts").load("posts.php", {from_user: fm}, function(){
});

In this message list, I have a function to remove messages from the list:

    //START POST DELETE FUNCTION    
$("form#deletepost").submit(function() {

// we want to store the values from the form input box, then send via ajax below
var deleteid = $('#deleteid').attr('value');

//START AJAX    
$.ajax({
    type : "POST",
    url: "process.php",
    data: {deleteid : deleteid},
    error: function(){ 
    alert("Mesage could not be posted at this time. Please try again.");
    },
    success: function(){ 

            $("#microblogposts").load("posts.php", {from_user: fm}, function(){
            //alert("posts have been loaded");
            });

            $("#latestpost").load("latestpost.php", {from_user: fm}, function(){
            //alert("latest posts have been loaded");
            });

    }
    //END SUCCESS FUNCTION
});
return false;
//END AJAX  

}); 
//END POST DELETE FUNCTION  

I want the code to update some elements in the DOM when AJAX was successful, but it does not work, it can still be done.

+3
source share
1 answer

Thanks for helping jigfox. The problem was the variables where they were empty, so the content did not load.

+1
source

Source: https://habr.com/ru/post/1762072/


All Articles