带有链接的表单提交
我正在用经典 ASP 构建一个网页,该网页最多包含 10 个包含在表单中的链接,并由 CSS 控制,以提供翻转和彩色块的外观。单击块/链接时,我需要向用户下载 Zip 文件,同时将表单提交回自身,以便可以使用此信息更新数据库。然后该页面可供用户下次下载。
我可以将 zip 文件下载到新窗口,但表单提交不一致,也许您可以提供建议。我在网上搜索了几周,但没有找到答案。
每个链接的构造如下
<table cellspacing="0" cellpadding="0" width="250" border="0">
<form action="<%=request("script_name")%>" method="post" id="form1" name="form1">
<tr style="height:18px;" bgcolor="#e8e8e8">
<td bgcolor="#e6e6e6" align="center">
<a href="http://.....URL of Zip file" onClick="javascript:document.forms(0).submit();" class="dload">DOWNLOAD</a>
<input type="Hidden" name="trak" value="1">
</td>
</tr>
</form>
</table>
I am constructing a web page in classic ASP which has up to 10 links wrapped in forms and controlled by CSS to give a rollover and the appearance of a coloured block. When the block/link is clicked I need to download a Zip file to the user and at the same time submit the form back to itself so that a database can be updated with this information. The page would then be available for the next download by the user.
I can download the zip file to a new window but the form submits inconsistantly, perhaps you could advise. I have searched the web for a couple of weeks and not found an answer.
Each link is constructed as below
<table cellspacing="0" cellpadding="0" width="250" border="0">
<form action="<%=request("script_name")%>" method="post" id="form1" name="form1">
<tr style="height:18px;" bgcolor="#e8e8e8">
<td bgcolor="#e6e6e6" align="center">
<a href="http://.....URL of Zip file" onClick="javascript:document.forms(0).submit();" class="dload">DOWNLOAD</a>
<input type="Hidden" name="trak" value="1">
</td>
</tr>
</form>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
document.getElementById("form1").submit()
比假设此表单始终是文档中的第一个表单稍微稳健一些。我认为它的跨浏览器兼容性也更好一些。Using
document.getElementById("form1").submit()
would be slightly more robust than assuming this form will always be the first in the document. I think it's slightly more cross-browser compatible, too.试试这个:
Try this:
忘记表格。您正在进行日志记录,这对服务器来说并不是重大变化。将 ASP 切换为期望 GET 而不是 POST,然后只需执行以下操作:
让日志记录脚本返回 zip 文件(通过读取数据并直接返回它或使用 302 重定向进行响应)。
不要尝试让浏览器对一个链接发出两个 HTTP 请求,这样只会导致混乱。
Forget about forms. You are doing logging, that is not a significant change on the server. Switch the ASP to expect GET instead of POST then just do:
And have the logging script return the zip file (either by reading the data and returning it directly or responding with a 302 redirect).
Don't try to get the browser to make two HTTP requests for one link, that way just leads to a nasty mess.