$ .post表单与Facebox和重定向 [英] $.post form with facebox and redirect

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

问题描述

将Facebox与.NET(Web窗体)一起使用很痛苦-这个主要的HTML网站是由其他人设计的.我可能也有IIS(7.5)问题. Facebox弹出窗口位于单独的文件login.html中,该文件从index.html调用:

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'
});

和打开它的链接

<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>

要使用用户名和密码(login.html)提交的表单:

The form to be submitted with username and password (login.html):

<form name="login" method="post" action="#" onsubmit="return false;">

,并且经过验证(此方法有效)后,它将发布到login.aspx(login.html):

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();
    }
});

该表格发布.我可以在Visual Studio中的login.aspx的Page_Load方法中对其进行调试. Page_Load方法的最后一行是:

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");

但是,Facebox弹出窗口仍然存在. Firebug显示了该帖子,它点击了login.aspx的Page_Load方法,并且Facebox弹出窗口没有显示任何位置. 但是, Firebug在XHR请求的响应"选项卡中显示了两次渲染的welcomepage.html.我以为$ .post会定期回发.为什么我的浏览器实际上没有重定向.

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.

尝试修复

如果我将login.html中的表单更改为action='login.aspx',则会出现405.0错误方法(,但是它试图发布到index.html,是吗?).而且我不知道如何在Windows 7的IIS 7.5中解决此问题.在本地部署到IIS时,在Visual Studio 中会收到此错误.我已经读过它可能与脚本映射,处理程序有关,或者我是从an发帖的事实,但是我找不到足够的解决方法.这里有什么想法吗?如果我可以确定Facebox重定向,则可能不需要此修复程序.

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.

推荐答案

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() 不会进行定期回发,它会执行AJAX POST,这很可能是造成混淆的原因,如果您打算进行定期的页面更改回发,则应该使用标准的<form>.

$.post() does not do a regular postback, it does an AJAX POST, that's probably the source of the confusion, you should use a standard <form> if you intend to do a regular, page-changing postback.

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

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