在一个旧网站上我刚刚被修改了,我添加了一些VBScript(不熟悉它,只是试图伪造它直到我制作它)如下:
'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()
ReturnMsg = "Made it to IsNewBusiness logic"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
在我添加“End If”行之前,它失败了 - 导航到该页面给了我一个错误的消息。
添加“End If”之后,错误消息已经消失,但是javascript警报(暂时只是让我知道代码确实运行了)没有显示,为什么不显示?
使用F12(我必须在兼容模式下在IE11中运行),我查找了这个文件,以便我可以在其中放置一个断点,但它似乎没有使它自己可用。
根据Archer的回答,我用以下内容替换了我的代码:
ReturnMsg = "IsNewBusiness logic not reached"
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
ReturnMsg = "Made it to IsNewBusiness logic"
End If
adoRS.Close()
%> <!-- this indicates the end of aspx - start of markup -->
<script type="text/javascript">
alert("<%= ReturnMsg %>");
</script>
<%
...但是当我导航到该页面时,我仍然看不到任何警报。
答案 0 :(得分:1)
好的,首先要做的事情。您不需要在aspx文件中使用Response.Write()
,因为这是在执行后将作为标记发送到浏览器的内容。您可以在其中放置任何类型的纯文本标记,包括Javascript。所以,你可以改变你现在拥有的东西......
'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()
ReturnMsg = "Made it to IsNewBusiness logic"
%> <!-- this indicates the end of aspx - start of markup -->
<script type="text/javascript">
alert("<%= ReturnMsg %>");
</script>
<% <!-- this indicates end of markup but is only required if you have any further aspx code -->