readyState 4-可以重定向网址吗? [英] readyState 4 - redirect url is that possible?
问题描述
我想知道当你有readyState == 4时是否有可能重定向到页面.
I was wondering if it is possible when u have readyState == 4, to redirect to a page..
//load the send form
if (sendRequest) {
sendRequest.open("POST", urlRequest, true);
sendRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
sendRequest.setRequestHeader("Connection", "close");
sendRequest.onreadystatechange = displayStatus;
sendRequest.send(sendData);
} else {
alert("fails"); //alert if request fails
}
}
function displayStatus() {
if (sendRequest.readyState == 4) {
alert("send");
// redirect to thank you page?
} else {
alert("send fails");
} //end readyState
}
我不会得到200
所以在readyState 4上,我想重定向到页面,发送表格后,我想重定向到页面.在php邮件功能上,<?php标头(位置:"url");?>
不起作用所以我真的需要在ajax/javascript中使用它...
so on readyState 4 , i want to redirect to a page,
after the form is sended i want to redirect to a page.
on php mail function, <?php header(location: "url"); ?>
is not working
so i really need to have it in ajax/javascript...
目前,它只是无法正常工作.有什么建议吗?
currently it just not working. any suggestion?
推荐答案
谢谢J.Romero.通过您的输入,我已经找到了问题所在,并构造了一些不同的脚本.
Thank you J.Romero. With your input i have trace down the problem and construct the script a bit different.
这不是跨域问题-正确设置了这些设置.警报框是正确的,并且sendRequest是全局的,因此所有函数都可以调用它.
It was not a cross domain issue - those settings are set properly. Alert box is correct and the sendRequest is global, so all functions can call it.
这仅导致1条故障,形式为.有 onSubmit ="return checkForm(this);"action ="
它应该是 onSubmit ="checkForm(this);返回false;"action ="
This lead to only 1 fault, and that is in the form.
had onSubmit="return checkForm(this);" action=""
It should be onSubmit="checkForm(this); return false;" action=""
与onSubmit事件一起返回的值为false,因此该表单不会像往常一样提交.并正确构建js和ajax以完成发送表单.验证表单->确定->准备表单->调用ajax->所有有效->发送表单->重定向到谢谢"页面.
with the onSubmit event return a value of false, so the form doesn't submit as usual. and constructing the js and ajax properly to finalize the send form. validate the form -> when ok -> prepare the form -> call ajax -> all valid -> send form -> redirect to thank you page.
谢谢大家的帮助!
这篇关于readyState 4-可以重定向网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!