$.post form with facebox and redirect

老子叫甜甜 提交于 2020-01-16 11:27:26

问题


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.


回答1:


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 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.



来源:https://stackoverflow.com/questions/3865535/post-form-with-facebox-and-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!