douwo8140 2018-04-30 22:58
浏览 91
已采纳

通过三个操作提交表单

I have a three-button form. First button "only Save document", second button "only generate PDF" and third button "Save document and Generate PDF".

only Save button - just submitting form - works fine

<form method="post">
  <button type="submit" name="save">
  <input>....
</form>

only Generate PDF button - change form action and target with simple jquery and send it to PDF generator - also works fine

<form method="post">
   <button type="submit" name="generate" id="generate">
   <input>....
</form>

<script>
$('#generate').click(function(){
   $('form').get(0).setAttribute('action', './library/pdf/generator.php');
   $('form').get(0).setAttribute('target', 'blank'); 
   });
</script>

Save document and Generate PDF button - here i need merge both in one on one click... submit + save data and open PHP generator in new tab(window) .. both with same POST data ... Any ideas? I'm stuck here

EDIT: Tried this callback without luck.. it open only pdf generator (im begginer in jquery, so maybe its nonsence)

$(function() {
$('#saveandgenerate').click(function(){
   $('form').get(0).setAttribute('action', './library/pdf/generator.php');
   $('form').get(0).setAttribute('target', 'blank');
   $('form').get(0).submit(function(){ 
      $('form').get(0).setAttribute('action', '');
      $('form').get(0).setAttribute('target', '');
      $('form').get(0).submit();
      }); 
   });
});
  • 写回答

2条回答 默认 最新

  • duanbishai5271 2018-05-01 11:49
    关注

    Working solution:

    $(function() {
    $('#save_and_generate').click(function()
        {
        $('form').get(0).setAttribute('action', './library/pdf/generator.php');
        $('form').get(0).setAttribute('target', 'blank');
        $('form').get(0).submit();
        setTimeout(function() {
            $('form').get(0).setAttribute('action', '');
            $('form').get(0).setAttribute('target', '');
            $("button#save").trigger('click');
            },100); 
        });
    });
    

    Submit with "Save and generate PDF" > change form atributes and open corectly new window with PDF > After 100 timeout change form atributes to default > trigger "only Save" button

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!