[英]Redirecting after a AJAX form post
So I am currently investigating an issue a friend came to me with. 因此,我目前正在调查一个朋友来找我的问题。 I really don't have a solid understanding of either
AJAX
or jQuery
. 我对
AJAX
或jQuery
都没有真正的了解。 Near from what I can tell, when this form is posted, it is going to the current address/set_var.cgi
with the index of 94
and is being redirected to currentaddress/scale405.html
. 据我所知,在发布此表单时,它将转到索引为
94
的当前address/set_var.cgi
,并被重定向到currentaddress/scale405.html
。 He wants to be able to set the address in the second input to an actual address like www.google.com
so the user is redirected to a different site after the form post. 他希望能够将第二个输入中的地址设置为实际地址,例如
www.google.com
以便在表单发布后将用户重定向到其他站点。 I've tried looking in the jQuery
and AJAX
scripts and I am at a total loss. 我试图在
jQuery
和AJAX
脚本中查找,我全然不知所措。
if someone would like to take a look, its www.gloryfeed.com
. 如果有人想看看,请
www.gloryfeed.com
。
<form name="requestPrint" action="http:set_var.cgi" method="POST">
<input name="value" type="hidden" size="8" value="1">
<input type="hidden" name="page" value="scale405.html">
<input type="hidden" name="index" value="94">
</form>
So I guess my question is, is there a way to format the URL
that is entered into that value so it redirects properly without having to change the AJAX
and jQuery
? 所以我想我的问题是,有没有一种方法可以格式化输入到该值中的
URL
,以便在不更改AJAX
和jQuery
情况下正确地重定向?
The redirect itself is very easy: 重定向本身非常简单:
doc.location = redirect_url;
The redirect_url
would come from the AJAX data. redirect_url
将来自AJAX数据。 It depends on whether you get JSON or XML as data. 这取决于您是否将JSON或XML作为数据。 If set, then redirect.
如果设置,则重定向。
With XML you can use jQuery to retrieve the data. 使用XML,您可以使用jQuery检索数据。 Maybe something like that (untested):
也许像这样(未经测试):
redirect = jQuery("redirect", result.jqxhr.responseXML);
You may have to handle all sorts of situations, the primary one being errors. 您可能必须处理各种情况,主要是错误。 If the form you just sent has a missing field, you probably want to generate an error instead of a redirect.
如果刚发送的表单缺少字段,则可能要生成错误而不是重定向。 But the basics is pretty simple as shown above.
但是基础非常简单,如上所示。
I wrote a server_access.js
script that handles redirects, errors, sending data both ways... It's a plugin part of Snap! 我写了一个
server_access.js
脚本来处理重定向,错误,双向发送数据……这是Snap的插件部分! Websites . 网站 。
As a side note, using a Location: redirect_url
in the HTTP header won't help. 附带说明一下,在HTTP标头中使用
Location: redirect_url
将无济于事。 The AJAX response won't ever trigger a redirect, which is by design. AJAX响应永远不会触发重定向,这是设计使然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.