2013-09-21 24 views
0

当我尝试显示在同一页面它工作正常的数据,但我需要打开一个新窗口/标签与附加到页面成功的Ajax调用,打开一个新的窗口,并追加数据

$.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'); 
    } 
}); 
数据

这是我的jsp页面呼吁成功

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 
    }); 
} 

方法的代码是

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

你需要寻找在弹出的上下文中的'#报告table'。试试:'var popup = window.open(“details.htm”); table = $('#Report table',popup.document);' –

回答

0

试试这个下面的代码

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 
}); 

}

您可以参考以下链接:here

相关问题