Miranda
Miranda

Reputation: 259

show div on closing the pop up using location.reload() is used or any alternative

i am using a jquery ui dialog to show the details and there is an anchor tag delete which is used to delete the record from that pop up, and showing messages after successful deletion or unsuccessful deletion, but the problem i am facing is when i tried to close the pop up using location.reload as usual it is refreshing the page and the message i have displayed is also gone as ecause page refreshed. i have tried the alternate as just close the jquery ui dialog but still the same issue. please help to ged rid of that or any alternative. here is my code.

code for details pop up

$(".details").click(function () {
        event.preventDefault();
        var $buttonClicked = $(this);
        var name = $buttonClicked.attr('name');
        var id = $buttonClicked.attr('data-id');
        var divDetail = $("#detailsRolePlace");// div to open in dialog
        $.ajax({
            type: "GET",
            url: RoleDetailPostBackURL,
            contentType: "application/json; charset=utf-8",
            data: { "id": id },
            datatype: "json",
            success: function (data) {
                divDetail.html(data);
            }
        });
        var winW = $(window).width() -620;
        divDetail.dialog(
                {
                    autoOpen: true,
                    position: {
                        position: [0, 28]
                    },
                    height: "auto",
                    width: winW,
                    resizable: false,
                    resizable: false,
                    title: name,
                    modal: true,
                    open: function () {
                        divDetail.load();
                        divDetail.css('overflow', 'hidden');
                    },
                    buttons:
                    [

                       {
                           text: "Close",
                           "class": 'btn-success',
                           click: function () {
                               $(this).dialog("close");
                           }
                       }
                    ]
                });
    });

here is my script for delete the record from the dialog

$('a.removeThisRole').click(function () {
        if (confirm("This role will be deleted! Are you sure to delete this role?")) {
            var ids = new Array();
            ids.push(Number($(this).closest('ul').attr('id')));
            var myData = JSON.stringify({ RoleId: ids, action: "Delete" });
            changeAccountStatus(myData);
        }
        return false;
    });
function changeAccountStatus(myData) {
    $.ajax(
    {
        type: "POST",
        url: DeletePostBackURL,
        contentType: "application/json; charset=utf-8",
        data: myData,
        datatype: "json",
        success: function (data) {
            $(".dummyMessageHead").fadeIn("fast");
            $(".dummyMessageHead").html(data.message);
            $('.dummyHiddenDeletedRoleIds').each(function () {
                $("Input:checkbox[value=" + this.value + "]").closest('tr').remove();
            })
        }
        complete: function () {

            //$(".ui-front").hide();
            //$(".ui-dialog ").hide();
            location.reload(false);

        }
    });

view where message is showing in a div

<script src="~/Scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    var DeletePostBackURL = '@Url.Action("RoleLists", "Role")'    
</script>
 @using (Html.BeginForm("RoleLists", "Role", FormMethod.Post))
{
    <div class="row" style="margin:0px 0px 0px 0px;">
        <div class="dummyMessageHead col-md-12 col-sm-12">
            @Html.parseHtml(ViewData["MessageText"] != null ? ViewData["MessageText"].ToString() : "")
        </div>
    </div>  
 }
<div id="detailsRolePlace">

 </div>
<script src="~/Scripts/Role.js"></script>

Upvotes: 0

Views: 228

Answers (1)

Reshav
Reshav

Reputation: 545

Instead of using location.reload(false); try to close your dialog in your case it should be like.

$("#detailsRolePlace").dialog("close");

hope this will help.

Upvotes: 1

Related Questions