子窗口关闭时刷新父窗口中jqwidgets的Grid

来源:互联网 发布:数据分析培训课程 编辑:程序博客网 时间:2024/06/15 17:28
$.ajax({
                        type : "POST",
                        cache : false,
                        dataType : "json",
                        contentType:"application/json",
                        data : JSON.stringify(entity),
                        url : url,
                        error : function(jqXHR, textStatus, errorThrown) {
                            if (jqXHR.status == 401 || jqXHR.status == 403
                                    || jqXHR.status == 302) {
                                window.location.href = "./index.jsp";
                            } else if (jqXHR.status == 400) {
                                alert(jqXHR.responseText);
                            } else {
                                alert(jqXHR.responseText);
                            }
                            return false;
                        },
                        success : function(data) {
                            if (window.confirm("操作成功!是否关闭页面?")) {
                                if(window.opener.listops == 'edit'){
                                    var selectedId = window.opener.listId;

                                    var commit = window.opener.$("#queryResultGrid").jqxGrid('updaterow', selectedId, data);

                                    window.opener.$("#queryResultGrid").jqxGrid('updatebounddata');

                                }else if(window.opener.listops == 'add'){

                                    var commit = window.opener.$("#queryResultGrid").jqxGrid('addrow', null, data);

                                    window.opener.$("#queryResultGrid").jqxGrid('updatebounddata');

                                }
                                window.close();
                            } else {
                                entity = data;
                            }
                        }

                    });


============================================================

opener即谁打开我的,比如A页面利用window.open弹出了B页面窗口,那么A页面所在窗口就是B页面的opener,在B页面通过opener对象可以访问A页面。
parent表示父窗口,比如一个A页面利用iframe或frame调用B页面,那么A页面所在窗口就是B页面的parent。
在JS中,window.opener只是对弹出窗口的母窗口的一个引用。比如:

a.html中,通过点击按钮等方式window.open出一个新的窗口b.html。那么在b.html中,就可以通过 window.opener(省略写为opener)来引用a.html,包括a.html的document等对象,操作a.html的内容。假如这个 引用失败,那么将返回null。所以在调用opener的对象前,要先判断对象是否为null,否则会出现“对象为空或者不存在”的JS错误。

window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为:
window.opener.document.getElementByIdx("name").value = "输入的数据";


0 0
原创粉丝点击