提交后HTML表单重定向 [英] HTML Form Redirect After Submit

查看:390
本文介绍了提交后HTML表单重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表单代码:

 < form enctype =multipart / form-dataname =upload-文件method =postaction =http://example.com/upload> 
< div class =formi>
< input type =submitvalue =OKclass =link_but/>
< / div>
< div class =upltitle =Upload>< img src =http://example.com/example.pngalt =style =vertical-align:middle; />上传
< input type =filename =filesize =1class =uponchange =document.getElementById('text-link-input')。value =串(THIS.VALUE).replace( 'C:\\fakepath\\', '')/>
< / div>
< / form>

现在,我想在提交表单数据后将提交者重定向到我选择的任何页面,但该行为驻留在另一个我无法编辑的网站上。在将数据提交到该网站后,是否可以将用户重定向到任何页面?



从一些Google搜索结果中,我发现了这一点。添加以下代码:

  onSubmit = window.location ='http://google.com'

这没有奏效。也许我没有正确实施它?这是我做的:

 < form enctype =multipart / form-dataname =upload-filemethod =postonSubmit = window.location ='http://google.com'action =http://example.com/upload> 

另一个人说添加一个隐藏字段应该是可行的:

 < input type =hiddenname =redirectvalue =http://your.host/to/file.html> 

我应该如何实现这是我的代码?



建议和帮助等待... 解决方案

试试这个Javascript(jquery)代码。它对外部URL的ajax请求。使用回调函数来触发任何代码:

 < script type =text / javascript> 
$(function(){
$('form')。submit(function(){
$ .post('http://example.com/upload',function() {
window.location ='http://google.com';
});
return false;
});
});
< / script>


This is my form code:

<form enctype="multipart/form-data" name="upload-file" method="post"  action="http://example.com/upload">
    <div class="formi">
        <input id="text-link-input" type="text" name="url" class="link_form" value="your link"  onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"   />
        <input type="submit" value="OK" class="link_but" />
    </div>
    <div class="upl" title="Upload"><img src="http://example.com/example.png" alt="" style="vertical-align:middle;"/>Upload
        <input type="file" name="file" size="1" class="up" onchange = "document.getElementById('text-link-input').value = String(this.value).replace('C:\\fakepath\\','')"/>
    </div>
</form>

Now, I want to redirect the submitter to any page of my choice after the form data has been submitted, but the action resides on another website where I cannot edit. Is it possible to redirect the user to any page after he has submitted the data to that site?

From some Googling, this is what I have found. Adding this to form code:

onSubmit=window.location='http://google.com'

This didnt work. Maybe I didnt implement it correctly? This is what I did:

<form enctype="multipart/form-data" name="upload-file" method="post" onSubmit=window.location='http://google.com' action="http://example.com/upload">

Another person says adding a hidden field should work:

<input type="hidden" name="redirect" value="http://your.host/to/file.html"> 

How should I implement this is my code?

Suggestions and help awaited...

解决方案

Try this Javascript (jquery) code. Its an ajax request to an external URL. Use the callback function to fire any code:

<script type="text/javascript">
$(function() {
  $('form').submit(function(){
    $.post('http://example.com/upload', function() {
      window.location = 'http://google.com';
    });
    return false;
  });
});
</script>

这篇关于提交后HTML表单重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆