简体   繁体   English

Javascript错误......我想

[英]Javascript error… I think

I've been trying to fix this for two hours straight and I can't figure it out. 我一直试图解决这个问题两个小时,我无法弄明白。

onclick = "location='exceltest.asp?vanjaar=<%=vanjaar%>&vanmaand=<%=vanmaand%>&vandag=<%=vandag%>&totjaar=<%=totjaar%>&totmaand=<%=totmaand%>&totdag=<%=totdag%>'"

That line of code is in an < input type="button" /> attribute. 该行代码位于<input type =“button”/>属性中。 The button links to a page where an Excel download should be triggered. 该按钮链接到应该触发Excel下载的页面。 The values in the URL are from- and to-date-parts. URL中的值是from和date-parts部分。 (year, month, day) (年月日)

this: 这个:

onclick = "location='exceltest.asp?fromdate=<%=fromdate%>&todate=<%=todate%>'" /> 

does not work, because somehow IE7 reads the date (eg. 2008/1/1) wrong. 不起作用,因为IE7以某种方式读取日期(例如2008/1/1)错误。 Something to do with the slashes I think. 我认为与斜杠有关。

But when I try to click the button in IE and thus download the generated file, Internet explorer tries do download the file 但是当我尝试单击IE中的按钮并因此下载生成的文件时,Internet Explorer会尝试下载该文件

exceltest.asp?vanjaar=2008vanmaand=1vandag=1totjaar=2008totmaand=2totdag=1 exceltest.asp?vanjaar = 2008vanmaand = 1vandag = 1totjaar = 2008totmaand = 2totdag = 1

instead of the excel file I want. 而不是我想要的excel文件。
FF offers to download the excelfile, but gives (in that excelfile) an overview of an htmlpage with an errormessage telling me my query is wrong (Item cannot be found in the collection corresponding to the requested name or ordinal.) But that CAN'T be, I'm using that exact same query elsewhere, using the same (but restarted) connection. FF提供下载excelfile,但给(在那个excelfile)一个htmlpage的概述,错误消息告诉我我的查询是错误的(项目不能在对应于所请求的名称或序号的集合中找到。)但是不能是的,我在其他地方使用完全相同的查询,使用相同(但重新启动)的连接。

This is the bit of code I use to instantiate the download of the file: 这是我用来实例化文件下载的一些代码:

Response.Buffer = TRUE  
Response.ContentType = "application/vnd.ms-excel"  
Response.AddHeader "content-disposition", "attachment; filename=overicht.xls"  

There might actually being to things going on here, but I am most insterested in why IE wants to download the asp page and FF offers the right download. 实际上可能会发生这样的事情,但我最感兴趣的是IE为什么要下载asp页面而FF提供正确的下载。

The & inside onclick="" should be html-encoded to &amp; & inside onclick=""应该被html编码为&amp;

If fromdate contains slashes you're probably safest to url-encode that as well (though you seem to contradict that with your example URL). 如果fromdate包含斜杠,那么你也可能最安全地对url进行编码(尽管你似乎与你的示例URL相矛盾)。

Something that might help: Server.URLEncode 可能Server.URLEncode东西: Server.URLEncode

fromdate=<%=Server.URLEncode(fromdate)%>

But, your Excel file error -- Item cannot be found in the collection corresponding to the requested name or ordinal. 但是,您的Excel文件错误 - 在请求的名称或序号对应的集合中找不到项目。 -- is from Recordset.Fields() . - 来自Recordset.Fields() You're trying to grab a field that isn't available -- either a column name that isn't in your query or an index that's beyond your column count. 您正试图获取一个不可用的字段 - 您的查询中不存在的列名称或超出列数的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM