Submit a post with reload of just one div

0

I have a form that I want to pass via POST, but without reloading the entire page, after submitting the information, I wanted a div to reload its content, I have the following code:

<script>
        $(function()
        {
            $("#issuedButton, #expiredButton, #activeButton, #revokedButton").click(function(){
                var dataString = $("#searchByTime").serialize();
                $.ajax({
                    type: "POST",
                    url: "index",
                    data: dataString
                });
                $("#reload").load("index #reload");
                return false;
            });
        });
</script>

POST is being sent, however, I do not know if reload is not being done, or is being done without updating the information with data received via POST. Follow the div:

<div id="reload">
    <?php var_dump($this->searchbyorganization); ?>
</div>

You are in a var dump just for debugging. I use the Zend Framework, so the logic is in another controller class.

    
asked by anonymous 30.11.2017 / 19:05

1 answer

2

As indicated in the comments do not load , instead implement the successful handler with done or success and in that handler in> html of the <div> that matters.

Example:

$("#issuedButton, #expiredButton, #activeButton, #revokedButton").click(function(){
    var dataString = $("#searchByTime").serialize();
    $.ajax({
        type: "POST",
        url: "index",
        data: dataString
    }).done(function(dados){ //done em vez de load
        $("#reload").html(dados); //atribuir o conteúdo do div com a função html()
    });

    return false;
});

Note that I am assuming that the data sent from the php page is already the updated html to replace in the content of <div id="reload">

    
01.12.2017 / 00:55