How to pass the value to the parent page when the child page is reopened in the parent page and the child page is closed

In the process of java development, there are many and common situations in which child pages appear in the parent page, but the way to pass values ​​between the two pages is not the same. Today, during the development process, I have no problem finding myself I can't pass the value of the child page to the parent page. After a whole day of research, I finally found a solution. I wrote this article to prevent myself from forgetting, and I also exchanged and learned with the big guys. The writing is not good, please forgive me.
There are many ways to pass values ​​from the child page to the parent page. For example, the child page closes the child page after processing the data through the form form, and the parent page can be refreshed or the second jump in the background can realize the transmission of two data. Or directly make the child page into a hidden div, and js can operate two divs, so that the data of the parent and child pages can be communicated. This is also the method used by most webpages now, but the system I made today does not use such a method, but simply two pages. By clicking the button of the parent page, jump to the child page, and the child page gets the generated After coding, return the data to the parent page, as shown in the figure:
insert image description here
This is the parent page .
insert image description here
This is the child page
. I have studied many methods, and finally made a little change, modified the submit button to a button, and then used the callback callback in the method Function, the code is as follows:
Parent page:

$(this).attr("data-modal-size", "modal-full").popupDialog({
			title: "自助取号",
			url: url,
			callback: function () {
				backDate();
			}
		})

Subpage:

$("#purchaseDemandAdd4").on("click", function () {
        var _this=$(this);
        var year = $("#year").val();
        var purchaseType = $("#purchaseType").val();
        var serialNumber = $("#serialNumber").val();
        var projectCode = $("#projectCode").val();
        var poId = $("#poId").val();
        $.ajax({
            type: 'POST',
            url: WEB_ROOT + '/admin/purchase/purchase-contract/saveNumber',
            async:false,
            data: {
                year: year,
                purchaseType:purchaseType,
                serialNumber:serialNumber,
                projectCode:projectCode,
                poId:poId
            },
            dataType: "json",
            success: function(data) {
                var $dialog = _this.closest(".modal");
                var callback = $dialog.data("callback");
                if (callback) {
                    callback.call(_this);
                }
                Global.notify("success", "数据保存成功!");
            },
            error : function(){
                Global.notify("error", "数据加载处理失败,请尝试刷新或联系管理员!");
            }

        });

The code under success is the key code.

Guess you like

Origin blog.csdn.net/fzt12138/article/details/115008193