Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ajax success reload div content not working

There are many questions on this but no answer seems to be easy working.

I have a <form>with delete icons on every row. Now .on('click',functoin()..I have an ajax request like this:

$.ajax({
    type:"POST",
    url:"/update_rows.php",
    data:"delete_id="+$(this).attr("row"),
    success:function(data) {
        if(data) {
            //window.location.reload(true);
            //alert(data);
            $(".refresh-after-ajax").load("/cms/modules/mod11/inc/modinclude_admin.php .refresh-after-ajax");
        } else {
            //window.location.reload(true);
        }

    }
});

This works and update_rows.php looks like this:

<?php
    require_once($_SERVER["DOCUMENT_ROOT"].'/cms/inc/config.inc.php');
    global $navid,$DB_PRE,$lang_cms;
    $db=new DB();
    $sql='Delete FROM '.$DB_PRE.'_mod_ref_pricing  WHERE id='.intval($_POST['delete_id']);
    $db->query($sql);
?>

Now I don't want to use window.location.reload(true);cause I just want to update that container where a row has been deleted. As you cann see I tried with .load()to only reload that <div/>but no chance. alert(data) is empty because I'm not returning anything from update_rows.phpbut what should I return there to refresh the <div/>?

Thanks for advices!

like image 844
caramba Avatar asked Jan 28 '14 10:01

caramba


People also ask

How do I load a div after ajax success?

Just run inspect div after the method is completed. To avoid this issue use the following code: $("#divid"). load(" #divid > *");

How do I reload a div without reloading the whole page?

Use this. $('#mydiv'). load(document. URL + ' #mydiv');

How do you reload the same page after ajax success?

You can use the location. reload() method to reload or refresh an entire web page or just the content inside an element. The . reload() method can be triggered either explicitly (with a button click) or automatically.


1 Answers

OOOHHHHHH I've written the .load()at the wrong place now it works:

$.ajax({
    type:"POST",
    url:"/update_rows.php",
    data:"delete_id="+$(this).attr("row"),
    success:function(data) {
        if(data) {

        } else {
            $(".refresh-after-ajax").load(window.location + " .refresh-after-ajax");
        }

    }
});

Thanks for the help, the $(this).remove() would also have been a nice solution

like image 119
caramba Avatar answered Oct 14 '22 14:10

caramba