我有一个基本的ajax评论表单,带有文本区域和是/否单选对象。
- 如果选择"is",则发布用户的评论,然后 他们被带到一个新的页面。
- 如果选择“否”,评论将发布并保留在同一页面上。
实际情况是,当用户选择"is"时,评论不会发布,并且页面仍会重定向。
这是帖子脚本:
//
flag_yesno = getRadioValue('form_comments', 'flag_yesno');
request.open('POST', 'process.php?t=' + new Date().getTime());
request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
request.onreadystatechange = function()
{
if(request.readyState == 4)
{
// put response text in the comment_posts div
comment_posts.innerHTML = request.responseText;
}
}
// set up POST parameters
var params = "&foo=" + foo + "&bar=" + bar;
// send it on over!
request.send(params);
// redirect if needed
if (flag_yesno=='yes')
{
window.location = '/foo.php?foo='+foo;
}
有没有办法在 request.send()
被触发后处理重定向?看来重定向正在破坏该部分。
最佳答案
等待调用完成。等待“直到它被发射”是很难衡量的。
if(request.readyState == 4)
{
if (flag_yesno == 'yes')
{
// redirect if needed
window.location = '/foo.php?foo='+foo;
}
else
{
// put response text in the comment_posts div
comment_posts.innerHTML = request.responseText;
}
}
关于javascript - request.send() 之后重定向 - 请求未发布,页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24418471/