How do I reload the page after an AJAX call is done with a dialog?
Asked Answered
U

2

11

so I have a dialog UI with a form once a user click on a link it opens. Once they click "Add button" it create a AJAX call that submits the data into the database. What I need to add is reload() function to refresh the page.

How can I add the reload function?

I have tried to add windows.localtion.reload(); you can see it my code. That line does not work for some reason

//Update contact dialog box
    $( "#contact-edit" ).dialog({
    resizable: false,
    width: 500,
    modal: true,
    autoOpen: false,
    buttons: {
        "Update Info": function(e) {

        var formData = $('#edit-form').serialize();

        //submit record
        $.ajax({    
            type: 'POST',
            url: 'ajax/handler-contact-update.php',     
            data: formData,
            dataType: 'json',
            cache: false,
            timeout: 7000,
            success: function(data) {           

                $('#response-edit').removeClass().addClass((data.error === true) ? 'errorBox' : 'passBox').html(data.msg).fadeIn('fast');   

                if ($('#response-edit').hasClass('passBox')) {
                    $('#response-edit').fadeIn('fast');
                    $('#edit-form').hide();
                        $( "#contact-edit" ).dialog("close");
                        windows.localtion.reload();
                }       
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {

                $('#response-edit').removeClass().addClass('errorBox')
                            .html('<p>There was an<strong> ' + errorThrown +
                                  '</strong> error due to a<strong> ' + textStatus +
                                  '</strong> condition.</p>').fadeIn('fast');           
            },              
            complete: function(XMLHttpRequest, status) {            
                    $('form')[0].reset();
                    //$( this ).dialog( "close" );


            }
        }); 



        },
        Cancel: function() {
            $( this ).dialog( "close" );
        },
        Submit: function(){
            $('form')[0].submit();
        }
    }
});
Unthread answered 12/4, 2013 at 2:43 Comment(0)
W
25

You have a typo:

windows.localtion.reload();

Should be

window.location.reload();
Waistline answered 12/4, 2013 at 2:45 Comment(1)
Thanks I have no idea why I did not catch that. I guess too much code will kill you :(Unthread
B
7

You can try many ways to reload the page, I have tried few, at least few may help somebody.

location.reload()

location.reload(false)

window.location = window.location

window.location.reload();

If you using link then use this :

location.href = location.href
Byebye answered 12/7, 2016 at 3:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.