0

我在 ajax 事件的服务器端创建一个 word 文档,如果没有错误,我想将其推送下载作为响应。jquery ajax可以吗?我的代码如下所示

                $.ajax({
                       type: "POST",
                       url: 'docsx.php',
                       data: $("#edit_form").serialize(), // serializes the form's elements.
                       success: function(data)
                       {
                        **here should be fired the download** // show response from the php script.
                       },
                       error:function(){

                           alert('Es gibt ein Fehler bei Daten übetragung!');

                        }
                     });
4

3 回答 3

0
  <div id="Status_Update" title="Update your Status Here">
    <form method="post" action="update_status.php?<?php echo(SID); ?>" name="Status_form" id="Status_form">
      <span id="sprytextfield1">
      <label for="text1"></label>
      <label for="textfield6"></label>
      <textarea class="ns_tb" name="status_update_box" cols="60" placeholder="What is on your mind" style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; border: thin solid #0C0; border-radius:9px;"></textarea>
<span class="textfieldRequiredMsg">A value is required.</span></span>
      <input type="submit" name="status_update_button" id="button" value="Post" style=" background-color:#0C0; border-radius:9px;)"/>
      <a href="#" id="hide_status_box" tittle="Hide the Status Comment Box">hide</a>
    </form>
  </div>
于 2012-09-22T20:40:34.900 回答
0

我自己做过一次:您可以在 php 中生成文件,将其放在服务器上的某个位置,然后返回脚本的路径。接下来,创建一个隐藏的 iframe 并调用一个简单的脚本,该脚本只读取文件并返回它并设置适当的标头以强制下载。结果将是没有页面刷新的强制下载。

于 2012-09-22T14:21:26.963 回答
0

您不能使用 javascript 触发下载。只是不要为此目的使用 AJAX。使用标准表单提交到docsx.php脚本:

<form action="docsx.php" method="post">
    ... some input fields

    <input type="submit" value="Download" />
</form>
于 2012-09-22T14:23:18.213 回答