求一段asp和js代码错误原因
=============下面这段代码能正常更新,但弹不出提示框===========
<%Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from Affiche where id="&id
rs.open sql,conn,1,3
rs("Title")=Title
rs("Content")=content
rs.update
%>
<script language="javascript">
alert("新闻发布成功!");
</script>
<%
response.redirect "Admin_editAffiche.asp?id=4"
end if
%>
===========为什么该成这样就好使呢?==============
<%Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from Affiche where id="&id
rs.open sql,conn,1,3
rs("Title")=Title
rs("Content")=content
rs.update
%>
<script language="javascript">
alert("新闻发布成功!");
location.href="Admin_editAffiche.asp?id=4"
</script>
<%
end if
%>
第一段代码的alert为什么没起作用,请教原因
答案:response.redirect 执行时会将输出缓冲区清空,相当于你上面输出的JS代码在发到浏览器之前就被取消了.浏览器实际上只收到了一个跳转信息,并没有收到JS代码,自然不会弹出对话框.
其他:因为response.redirect "Admin_editAffiche.asp?id=4"是在服务端运行的,所以alert("新闻发布成功!");无法弹出就被跳转了。
而location.href="Admin_editAffiche.asp?id=4"是在客户端运行的,只有确认alert("新闻发布成功!");之后才到location.href="Admin_editAffiche.asp?id=4",也才跳转
上一个:求ASP高手修改代码。 首页新闻图变换 让其连接指定的页面 而不是一点击跑到新闻内容页
下一个:ASP程序求助:下面的代码是实现照片上传功能的,但是点上传按钮没有用,请高手帮忙!!