在空白/新页面中显示以下AJAX

Display the following AJAX in a blank/new page

本文关键字:AJAX 显示 空白 新页面      更新时间:2023-09-26

我想在新页面或空白页面中显示AJAX代码的部分,而不会在同一页面上的"旧" html代码下获得所请求的url。

d$(document).ready(function() {
        $("#bestello").submit(function() {
            if($("#nn").val() == "" || $("#vn").val() == "" || $("#strt").val() == ""){
                $("#response").html("Bitte füllen Sie alle Felder aus!");
            } else {
                $.ajax({
                    type: "POST",
                    url: "test.php",
                    data: "nn=" + $("#nn").val() + "&vn=" + $("#vn").val() + "&strt=" + $("#strt").val(),
                    success: function(msg)
                    {
                        $("#response").html(msg);
                    }
                });
            }
            return false;
        });
    });

else或$之后的所有内容。Ajax({应该显示在一个空白/新页面。我该如何解决这个问题?

您正在寻找弹出函数

将以下代码放入success函数

var w = window.open('', '', 'width=400,height=400,resizeable,scrollbars');
w.document.write(msg);
w.document.close(); // needed for chrome and safari

不使用ajax提交表单,而是允许使用表单的本地功能提交表单。将属性target='_blank' action='test.php' method='post'添加到表单中,以便它将使用post提交到test.php并在新选项卡/窗口中打开。

您仍然可以使用javascript来验证表单。你的代码看起来像这样:

$(document).ready(function() {
    $("#bestello").submit(function() {
        if($("#nn").val() == "" || $("#vn").val() == "" || $("#strt").val() == ""){
            $("#response").html("Bitte füllen Sie alle Felder aus!");
            return false;
        }
        return true;
    });
});

这将用javascript验证表单,只有当它通过验证时才允许它提交。(作为旁注,您应该确保您也做了一些服务器端验证)。