由于观看结果,我如何避免打开新窗口?

时间:2017-08-03 08:35:58

标签: javascript jquery ajax jquery-ui

  

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

     

我曾考虑使用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;
    });
});

1 个答案:

答案 0 :(得分:0)

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

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