Jquery 成功调用ajax后,打开一个新窗口并附加数据

Jquery 成功调用ajax后,打开一个新窗口并附加数据,jquery,ajax,Jquery,Ajax,当我尝试在同一页面中显示数据时,效果很好,但我需要打开一个新窗口/选项卡,其中包含附加到该页面的数据 $.ajax({ async : true, type : 'GET', cache : false, url : 'rest/getReport', data : 'startDate=' + fromDate + '&endDate=' + toDate, datatype : 'json', success : functio

当我尝试在同一页面中显示数据时,效果很好,但我需要打开一个新窗口/选项卡,其中包含附加到该页面的数据

$.ajax({
    async : true,
    type : 'GET',
    cache : false,
    url : 'rest/getReport',
    data : 'startDate=' + fromDate + '&endDate=' + toDate,
    datatype : 'json',
    success : function (data) {
        that.viewReport(data);
    },

    complete : function (data) {
          $('#search-box').find('img.waiting').css('visibility', 'hidden');
    }
});
这就是所谓的成功方法

viewReport : function (data) {
    var table;
    window.open("details.htm");
    table = $('#Report table');//#report is id of div in details.htm
    if (data.length == 0) {
        $('#Report .no-view-error').show();
        return;
    }
    table.empty();
    $.each(data, function (index, item) {
        var row = '<tr id="tkNo-' + item.num + '">';
        row += '<td>' +item.Date + '</td>';
        row += '<td>' +item.Type + '</td>';
        row += '<td>' +item.Num + '</td>';
        row += '<td>' +item.receivedDate + '</td>';
        row += '<td>' +item.doneBy + '</td>';
        row += '<td>' +item.comments + '</td>';
        row += '</tr>';
    table.append(row);//appending rows to table in the new page
    });
}
viewReport:函数(数据){
var表;
window.open(“details.htm”);
table=$(“#Report table”);/#Report是details.htm中div的id
如果(data.length==0){
$('#Report.no view error').show();
返回;
}
table.empty();
$。每个(数据、功能(索引、项目){
var行=“”;
行+=''+项.Date+'';
行+=''+项目类型+'';
行+=''+项.Num+'';
行+=''+项.receivedDate+'';
行+=''+项.doneBy+'';
行+=“+项目。注释+”;
行+='';
table.append(row);//在新页面中将行追加到表中
});
}
在我的jsp页面中,代码是

<div id="Report" class="showDetails">
<div class="error-box no-view-error">There are no details in this period.</div>
<table></table>
</div>

在此期间没有任何详细信息。
试试下面的代码

viewReport : function (data) {
var table;
var new_window = window.open("details.htm");
table = $(new_window.document).find('#Report table');//#report is id of div in details.htm
if (data.length == 0) {
    $('#Report .no-view-error').show();
    return;
}
table.empty();
$.each(data, function (index, item) {
    var row = '<tr id="tkNo-' + item.num + '">';
    row += '<td>' +item.Date + '</td>';
    row += '<td>' +item.Type + '</td>';
    row += '<td>' +item.Num + '</td>';
    row += '<td>' +item.receivedDate + '</td>';
    row += '<td>' +item.doneBy + '</td>';
    row += '<td>' +item.comments + '</td>';
    row += '</tr>';
table.append(row);//appending rows to table in the new page
});
viewReport:函数(数据){
var表;
var new_window=window.open(“details.htm”);
table=$(new#window.document)。find(“#Report table”);/#Report是details.htm中div的id
如果(data.length==0){
$('#Report.no view error').show();
返回;
}
table.empty();
$。每个(数据、功能(索引、项目){
var行=“”;
行+=''+项.Date+'';
行+=“+项目类型+”;
行+=''+项.Num+'';
行+=''+项.receivedDate+'';
行+=''+项.doneBy+'';
行+=''+项注释+'';
行+='';
table.append(row);//在新页面中将行追加到表中
});
}


您可以参考此链接:

您需要在弹出式上下文中查找
#报告表
。尝试:
var popup=window.open(“details.htm”);table=$(“#报告表”,popup.document)