- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何打开一个新窗口,然后使用 HTML\Javascript 触发表单提交?
注意:target="_blank"不是解决方案,因为它将响应重定向到新窗口,而我需要从新窗口触发提交操作。
最佳答案
我会保留“_blank”来触发新选项卡/窗口并使用 jQuery 和 Ajax 提交表单...
带有表单的标准 html 页面...
HTML
<form id="myForm">
<input name="input1" type="text" value="somevalue1"/>
<input name="input2" type="text" value="somevalue2"/>
<a href="whereEverYouWantToGo.php" target="_blank" id="myFormButton">Send</a>
</form>
<input id="result1" value=""/> <?php //use if only wanting to get result back ?>
本页使用了 jQuery...
jQuery
$(document).ready(function() {
$(document).on("click","#myFormButton", function() {
var str = $("#myForm").serialize(); // This grabs all your form inputs by name and creates a string e.g. input1=someValue1&input2=someValue2 which you can use later for grabbing the $_GET variables.
$.ajax({
cache: false,
url: 'ajax/your-ajax-page-to-submit-the-form.php?'+str,
type: 'POST',
dataType: 'json',
success: function(result) {
alert("success");
// Can get data from Ajax file by using array cretaed in the file (see below)
$('#result1').val(result['result1_from_ajax']);
},
error : function () {
alert("error");
}
});
});
现在是 Ajax 页面...
您的ajax页面要提交的表单.php
ob_start(); //at the very beginning start output buffereing
$var_input1 = mysqli_real_escape_string($dbc, $_GET['input1']);
$var_input2 = mysqli_real_escape_string($dbc, $_GET['input2']);
$q = "INSERT INTO my_table (column1, column2) VALUES ('$input1', '$input2')";
$dbc = mysqli_connect('localhost', 'root', 'password', 'DB_Name') OR die('Could not connect because: '.mysqli_connect_error());
$r = mysqli_query($dbc, $q);
// bof if you want to output any results or values back to jQuery
$var = array(
'result1_from_ajax' => $var_input1,
'result2_from_ajax' => $var_input2
);
// eof if you want to output any results or values back to jQuery
// Must have
ob_end_clean(); // right before outputting the JSON, clear the buffer.
echo json_encode($var);
关于javascript - 打开新窗口并提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53117501/
我正在尝试使用特定路线打开一个新窗口,但似乎路线页面未正确加载。将从FrmApprovalMain.js打开新的 Electron 窗口,并应使用FrmPOdet.js打开新窗口。但是,当它打开时,会
我对 Tkinter 比较陌生,我需要帮助。 当从父窗口单击按钮时,我创建了一个新窗口。新窗口是 def new_Window。但我似乎无法获取窗口中的信息,如下编码: from tkinter im
我正在尝试使用 Javascript 从空白 iframe 中创建一个重定向,该 iframe 将定向到新窗口或选项卡中的 URL。 更具体地说,我试图让一个 Facebook 标签指向我公司的网页,
在问这个问题之前,我确实搜索了很多。抱歉,如果这是一个简单的问题。 在我的 wxWidgets 应用程序中,我想从菜单选项中新建一个 wxHtmlWindow。 (我已经正确显示了我的主应用程序窗口)
我认为我不是很了解这个,因为我对 jquery 还很陌生。我有一个隐藏了 3 个食谱的页面。单击食谱 A 的链接时,它会以模式打开。我希望能够只打印食谱的内容。所以我打开一个新窗口(非模态)并尝试将食
我想在带有可滚动文本框的现有主 Windwoe 旁边创建一个新窗口。 我在主窗口中按下“打开新窗口”按钮,然后它应该会打开一个带有可滚动文本框的新窗口。 在 form2 中 在 WPF 中,您可以在主
我正在使用 Simple Icons 制作自定义 Pinterest Pin It 按钮,我正在使用 Pinterest Widget Builder 给我的链接。在默认的 Pin It 按钮上,它会
我的表单上出现一个确认对话框,单击“确定”后会将用户重定向到另一个页面。 但是,是否可以在新窗口中打开该页面(例如 target="_blank") 我正在使用的代码是: var answer=con
相关但处于休眠状态:Javascript to open URL within a new Tab和其他一些...... 我有一个客户坚持认为特定链接需要在新选项卡中打开,而不是在窗口中打开。它由表单
我遇到了 Android 问题 WebView , 我想用 target='_blank' 打开一个 URL在同一WebView ,就像所有其他的一样URLs正在开放。 另请注意,我重写了 WebVi
可以从 Controller 重定向到某个 url 并同时在新窗口中打开该 url 吗? 最佳答案 不是真的来自 Controller Action 。 重定向是带有 301/302 状态代码和 Ra
在 Electron vue 中,我想为每个新窗口创建新的 vue 实例。这工作正常,直到我想将路由器子组件加载到新窗口。例如我有条目 add: path.join(__dirname, '../sr
案例1: var printWindow = window.open("", "print_window"); if(printWindow) { printWindow.addEventLi
我需要使用 Javascript Window.Open 函数打开一个新的 (_blank) 窗口。 URL 编码的回车符/换行符 (%0A) 似乎不起作用。有谁知道解决这个问题?例如,我有以下 UR
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Imp
当 flash 有键盘焦点时,CTRL+T(新标签)和 CTRL+N(新标签)窗口)被闪光拦截。 有没有办法将这些事件传递给浏览器以便它们工作(打开新选项卡,打开新浏览器)或者是否有用于这些操作的 j
我有一个 ASP.Net MVC 页面,上面有一个非常简单的表单:一个文本框和一个提交按钮。该表单使用标准的 mvc BeginForm() 语法: 当直接打开页面时,一切正常。 但是,我们有另一个
如果您对此问题感兴趣,请阅读下面的更新 #2 ;) 假设我将此代码放入我的扩展程序的 JS 中。 var reader = { onInputStreamReady : function(in
我是一名优秀的程序员,十分优秀!