【问题标题】:How might I avoid opening a new window in due to watch results?如何避免因观看结果而打开新窗口?
【发布时间】:2017-08-03 08:35:57
【问题描述】:

请查看我的代码。由于观看结果,我想避免打开一个新窗口。我想避免在同一窗口中显示结果而不是当前内容。

我考虑过使用 AJAX 在 Dialog 窗口 (JQueryUI) 中显示结果 https://jqueryui.com/dialog/ 但我不知道怎么做?提前谢谢你:)

HTML:result_browser.html

<form class="form" method="post" id="resultbrowserform">

    <!--Something-->

    <button type="submit" class="btn btn-default"> Apply </button>
</form>

<div id="dialog" title="Details">
    <p></p>
</div>

JS:

$(function () { function serializeForm(form){...}

...

$('#resultbrowserform').submit(function () {
    $.ajax({
        type: 'POST',
            url: '/result_browser/data/',
            data:  serializeForm($('#resultbrowserform')),
            success: function (data, status, jqXHR) {
                $('#resultbrowsertablecontainer').remove();
                data = data.data;
                if (!data.length) {
                    window.alert('No data for selected time period');
                    return;
                }

                div = $('<div id="resultbrowsertablecontainer">');
                table = $('<table class="table table-striped">');
                header = $('<thead>');
                header.append($('<tr>')
                    .append( $('<th>').html('Die Id'))
                    .append( $('<th>').html('Application'))
                    .append( $('<th>').html('Result'))
                table.append(header);
                body = $('<tbody>');
                for (i = 0; i < data.length; i++) {
                    row = $('<tr>');
                    row.append( $('<td>').html(data[i].die_id));
                    row.append( $('<td>').html(data[i].application));
                    row.append( $('<td>').html(data[i].result));

                    <!--I would like to avoid opening a new window-->
                    link = $('<a>').attr('target', '_blank').attr('href', '/result_details/' + data[i].result_id + '/').html('Details');

                    row.append($('<td>').append(link));
                    body.append(row);
                }
                table.append(body);
                div.append(table);
                $('#resultbrowsercontainer').append(div);
            }
        });
        return false;
    });
});

【问题讨论】:

  • 只需删除这个就可以了:.attr('target', '_blank')

标签: javascript jquery ajax jquery-ui


【解决方案1】:

只需删除目标属性,它就会在自身内部打开:

<!--I would like to avoid opening a new window-->
link = $('<a>').attr('href', '/result_details/' + data[i].result_id + '/').html('Details');

【讨论】:

  • 我想避免在同一个窗口中显示结果而不是当前内容:)
  • 好的,那么您到底想要发生什么?不是很清楚
  • 我建议您编辑问题并选择您想要的选项
  • 我想在对话框窗口中显示结果:jqueryui.com/dialog
猜你喜欢
  • 1970-01-01
  • 2012-05-27
  • 2011-12-09
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-28
相关资源
最近更新 更多