$.post 表单,带有 Facebox 和重定向
将 Facebox 与 .NET(Web 表单)一起使用是很痛苦的——这个主要是 HTML 的网站是由其他人设计的。我可能也有 IIS (7.5) 问题。此 Facebox 弹出窗口位于一个单独的文件 login.html 中,该文件是从 index.html 调用的:
$k('a[rel*=example_2]').facebox_1({
loading_image : '/images/loading.gif',
close_image : '/images/closelabel.gif'
});
以及打开它的链接
<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>
使用用户名和密码提交的表单 (login.html):
<form name="login" method="post" action="#" onsubmit="return false;">
以及在验证后(此正在工作),它发布到login.aspx(login.html):
$('form[name="login"]').submit(function () {
var $loginForm = $('form[name="login"]');
if ($loginForm.valid()) {
$.post("Login.aspx", $(this).serialize());
} else {
$loginForm.validate();
}
});
表单发布。我可以在 Visual Studio 中的 login.aspx 的 Page_Load 方法中对其进行调试。 Page_Load 方法的最后一行是:
Response.Redirect("welcomepage.html");
但是,Facebox 弹出窗口仍然存在。 Firebug 显示该帖子,它命中了 login.aspx 的 Page_Load 方法,并且 Facebox 弹出窗口不会去任何地方。 但是, Firebug 显示welcomepage.html 在 XHR(嗯?为什么是 XHR?)请求的“响应”选项卡中呈现了两次。我以为 $.post 做了定期回发。为什么我的浏览器实际上没有重定向。
尝试修复
如果我将 login.html 中的表单更改为 action='login.aspx'
,我会收到 405.0 错误 method not allowed (但是,它正在尝试发布到index.html,嗯?)。我不知道如何在 Windows 7 上的 IIS 7.5 中修复此问题。在本地部署到 IIS 时,我在 Visual Studio 中遇到此错误和。我读过它可能与脚本映射、处理程序有关,或者我是从 发布的,但我找不到足够的修复程序。这里有什么想法吗?如果我能弄清楚 Facebox 重定向,我可能不需要此修复。
Using Facebox with .NET (Web Forms) is painful--this primarily HTML site was designed by someone else. I may have IIS (7.5) issues as well. This Facebox pop-up is in a separate file, login.html, that is called from index.html:
$k('a[rel*=example_2]').facebox_1({
loading_image : '/images/loading.gif',
close_image : '/images/closelabel.gif'
});
and the link to open it
<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>
The form to be submitted with username and password (login.html):
<form name="login" method="post" action="#" onsubmit="return false;">
and after it's validated (this is working), it posts to login.aspx (login.html):
$('form[name="login"]').submit(function () {
var $loginForm = $('form[name="login"]');
if ($loginForm.valid()) {
$.post("Login.aspx", $(this).serialize());
} else {
$loginForm.validate();
}
});
The form posts. I can debug it in Visual Studio in the Page_Load method of login.aspx. The last line of the Page_Load method is:
Response.Redirect("welcomepage.html");
But, the Facebox pop-up remains. Firebug shows the post, It hits the Page_Load method of login.aspx, and the Facebox pop-up doesn't go anywhere. BUT, Firebug shows welcomepage.html rendered twice in the Response tab of the XHR (huh? why XHR?) request. I thought $.post did a regular postback. And why isn't my browser actually redirecting.
Attempted Fix
If I change the form in login.html to action='login.aspx'
, I get a 405.0 error method not allowed (but, it's trying to post to index.html, HUH?). And I can't figure out how to fix this in IIS 7.5 on Windows 7. I get this error in Visual Studio and when deploying locally to IIS. I had read it may have to do with script mapping, handlers, or the fact that I'm posting from an but I can't find a sufficient fix. Any ideas here? If I can figure out the Facebox redirect, I might not need this fix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XmlHttpRequest 将透明地遵循重定向< /a>,这意味着
$.post()
进行的 AJAX 调用正在被重定向,并且跟随它......而不是实际的父页面。$.post()
确实不 进行常规回发,它执行 AJAXPOST
,这可能是混乱的根源,如果您打算进行常规回发,则应该使用标准XmlHttpRequests will transparently follow the redirect, which means the AJAX call that
$.post()
made is getting redirected, and following it...not the actual parent page.$.post()
does not do a regular postback, it does an AJAXPOST
, that's probably the source of the confusion, you should use a standard<form>
if you intend to do a regular, page-changing postback.