注册 登录
编程论坛 ASP技术论坛

请教 关于ASP提交数据后返回上一页并刷新 出现死循环问题

enjoy535 发布于 2011-04-11 22:05, 1328 次点击
RT...
我想实现在提交数据后页面自动返回上一页并刷新的过程,但是却发现在返回的时候页面不断地提交数据,进入了一个死循环,请高手帮我看看问题出在哪里,谢谢!

A页面提交表格代码:
<form name="form1" method="post" action="?type=addnew">
      <textarea name="txt_dayday" cols="50" class="list_tab_bian" id="txt_dayday"></textarea>
    <input name="Submit" type="submit" class="tab_bian" value="提交">
</form>

A页面添加数据代码,这段是在A页面前端的
<%
'新增记录================================
sub alarm_yes(word)    '确认框,点击确定后返回前一页并刷新
dim words
    words=word
    response.Write "<script language='javascript'>"
    response.Write "alert('"&words&"');"
    response.Write "history.back(-1);"
    response.Write "location.reload();"
    response.Write "</script>"
    response.End()
end sub

if request("type")="addnew" then
        conn.execute("insert into dayday (day_content) values ('"&trim(request.Form("txt_dayday"))&"')")
    if not err then
        call alarm_yes("添加成功!")
    else
        call alarm_no("添加失败!")
    end if
end if
%>

现在的问题就是当我在A页面提交数据后,A页面会提交记录到数据库里面,并且会弹出确认框,但我在点击确认框的“确定”按钮后,页面又再一次返回到之前的提交页面http://127.0.0.1/a.asp?type=addnew,并且会再弹出一个“重新提交数据”的“重试”框,如果点了“重试”,页面又会再次提交记录,再“确定”...不断进入一个死循环

请高人指点一下,到底是哪个地方出错了,为什么返回历史网址时还会自动带上提交的数据?能不能去掉?
我history.back(-1);、history.back(-2);、history.back();都测试过了,都不行
3 回复
#2
wangjy5002011-04-11 23:17
sub alarm_yes(word)    '确认框,点击确定后返回前一页并刷新
dim words
    words=word
    response.Write "<script language='javascript'>"
    response.Write "alert('"&words&"');"
    response.Write "window.location.href='a.asp';"
    response.Write "</script>"
    response.End()
end sub

#3
zznice2011-04-11 23:31
<form name="form1" method="post" action="?type=addnew">
改成
<form name="form1" method="post" action="a.asp">

response.Write "history.back(-1);"
改成
response.redirect "a.asp"

[ 本帖最后由 zznice 于 2011-4-11 23:35 编辑 ]
#4
enjoy5352011-04-12 21:37
谢谢楼上两位的帮助

其实我现在就是用的location.href方法:
sub alarm2(word,path)    '确定型弹出框,点击后跳转至目标页
dim words,where
    words=word
    where=path
    response.Write "<script language='javascript'>"
    response.Write "alert('"&words&"');"
    response.Write "location.href='"&where&"';"
    response.Write "</script>"
    response.End()
end sub

但我想编一个sub,可以随时调用,而且不用传递跳转url过去。
因为有时候会在分页列表的中间某页修改或者删除记录,那时候如果再传递一个url过去有点麻烦,所以我就想试试能不能在提交编辑后直接返回到历史url,然后再自动刷新,并且直接做成一个sub,方便随时调用,所以才试着编了上面一个页面...
1