Submit a single div Reload post

Asked

Viewed 1,026 times

0

I have a form that I want to pass via POST, but without giving Reload on the full page, after sending the information, I wish a div of that Reload in 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>

The 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>

It is in a var dump only for debug. I use the Zend Framework, so the logic is in another controller class.

  • 2

    I believe you should use the done or a Success from AJAX to get the post result

  • Just as you will not make a "Reload" of the div, you must rewrite your content with the return of the ajax post or make a new ajax request after the Success of your post.

1 answer

2


As stated in the comments do not load, instead implement the Handler successful with done or success and in that Handler update the html of <div> who 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 the data sent from the page php are already the html updated to replace in the content of <div id="reload">

  • So, he uploaded the entire html of the page into the div, what I wanted, is that he just refreshed the div, like in a Ubmit.

  • @Viniciusmacelai My answer works that way. The ajax is asynchronous and not force refresh, and is not done navigation in form Submit due to the return false;. Then the $("#reload").html(dados) recharges only the div you want

  • I think I understand what happened, in the variable "data" is all HTML page, I just changed to that $("#Reload"). html($(data).find("#Reload")); and it worked, thank you very much for the help.

Browser other questions tagged

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