为什么我的弹出表单没有由帖子数据填充


Why is my popup form is not being populated by post data

我有一个调度应用程序,用户可以单击表字段,它将在新页面中打开一个包含相应帖子数据的表单。我的用户已经决定这非常困难,现在需要查看时间表,并且表单是一个弹出窗口,以便他们可以同时看到两者。我有表单弹出窗口工作,但我的函数没有传递帖子数据。这是代码:

$(".main td:not(.jobCell):not(.tJCell)").click(function()
{
    var roleID = document.getElementById('roleID').value;
    var notDept =  $('.deptSelect').val();
    var myDept = $('#myDept').val();
    var $this = $(this);
    var colIndex = $this.cellPos().left;
    var preCol = colIndex % 2;
        if (myDept != notDept)
        {
            return;
        }

    if (preCol == 0)
    {
        colIndex = colIndex /2;
    }
    else
    {
        colIndex++;
        colIndex = colIndex /2;
    }
    var row = $this.parent('tr').contents('th:eq(0)').html();
    var departmentID = $(".deptSelect").val();  
    var headerObj = $(this).parents('.main').find('th').eq(colIndex);
    var toPass =   $.trim(headerObj.text());
    var picked = $("#picked").val();
    var testDate = new Date(picked + " " + row);
    var today = new Date();
    var today = new Date(today - 2*60*60*1000);

    if (testDate < today)
    {
        if (roleID > 2)
        {
        alert (today);
        alert("You Cannot Schedule a New Job in the Past!");
        }
        return;
    }
    var thisForm = '';
    if (roleID == 5)
    {
        thisForm = '../forms/tentativeJobForm.php';
    }
    else
    {
        thisForm ='../forms/newJobForm.php';
    }
    var f = document.createElement("form");
    f.setAttribute('class','jobTime');
    f.setAttribute('method','post');
    f.setAttribute('action',thisForm);
    var iii = document.createElement('input');
    iii.setAttribute('type','hidden');
    iii.setAttribute('name','departmentID');
    iii.setAttribute('value',departmentID);
    f.appendChild(iii);
    var i = document.createElement('input');
    i.setAttribute('type','hidden');
    i.setAttribute('name','sTime');
    i.setAttribute('value',picked + " " + row);
    f.appendChild(i);
    var ii = document.createElement('input');
    ii.setAttribute('type','hidden');
    ii.setAttribute('name','ast');
    ii.setAttribute('value',toPass);
    f.appendChild(ii);
    document.getElementsByTagName('body')[0].appendChild(f);
    if (roleID > 2)
    $('.jobTime').onsubmit(window.open(thisForm,null,"height=550,width=900,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100"));
    //$('.jobTime').submit();
    else
    return;
});

我知道该函数没有发布数据,所以我的问题是"如何让函数打开带有发布数据的弹出表单?

正在提交的表单和您的window.open()函数调用是对同一页面的两个不同请求,一个在同一窗口中,另一个在新窗口中。您的帖子数据会发送,但不会发送到您打开的新窗口。

最简单的方法是先打开窗口,并通过为其命名来将帖子数据发送到该窗口,然后告诉表单以定位新窗口。

在提交表单之前打开窗口:

window.open("","mynewwindow","height=550,width=900,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100");

为表单指定一个目标:

f.setAttribute('target','mynewwindow');

为了更加花哨和优雅,您可以使用jquery load()函数在当前页面的一部分中打开表单。您不需要以这种方式在 html 中创建表单元素。