【发布时间】:2018-04-06 04:16:26
【问题描述】:
TL;DR - 我想在弹出式覆盖而不是新选项卡中显示表单提交的最终结果。
我有一个在图像上写文本的表单。我点击提交,它会生成带有嵌入文本的图像到一个新页面。
我正在使用这个 jQuery 插件作为我的弹出覆盖:http://dev.vast.com/jquery-popup-overlay/
要触发弹出式覆盖,您必须将一个类分配给您想要触发的位置。所以我将它分配给表单的提交按钮:
<input type="submit" value="Submit" class="my_popup_open">
我创建了一个带有 id 的 div 来显示我希望弹出叠加层的位置:
<div id="my_popup">CONTENT GOES HERE</div>
$(document).ready(function() {
$(".submit").click(function() {
var imageFile = $("input#imgInp").val();
var topLine= $("input#toptextbox").val();
var bottomLine = $("input#bottomtextbox").val();
var dataString = 'file-to-upload='+imageFile+'&firstname='+topLine+'&lastname='+bottomLine;
$.ajax({
type: "POST",
url: "action.php",
data: dataString,
success: function() {
// Initialize the plugin
$('#my_popup').popup();
}
});
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/vast-engineering/jquery-popup-overlay/1.7.13/jquery.popupoverlay.js"></script>
<form action="">
First name:<br>
<input type='file' name="file-to-upload" id="imgInp">
<input type="text" name="firstname" id="toptextbox"><br> Last name:<br>
<input type="text" name="lastname" id="bottomtextbox><br><br>
<input type="submit" value="Submit" class="my_popup_open">
</form>
重述问题:因此,我如何在弹出式叠加层中显示表单的最终结果,而不是打开一个新页面到 action_page.php?
【问题讨论】: