views:

54

answers:

1

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  A: 

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.

Nick Craver
Thank you for the clarification. So, now it would seem IIS is my problem. Using a standard form with attribute `action='login.aspx'` produces the 405.0 error mentioned in the "Attempted Fix" section above. Is this because .html can't post to .aspx by default?
David
@David - What method were you using then?
Nick Craver
Post, as shown above in `form name='login'`. I also remove the submit function binding and the `onsubmit` attribute from the form.
David
I think the post is working now, but the other buttons on the page are broken. The other buttons fire `.click()` for other Facebox pop-ups. Should I start a new question for this?
David
@David - I would, or add the `click` handlers for those buttons...or if you have a link to the page that I can access that'd work too. Sorry for the delayed response, was away for a few hours.
Nick Craver
No problem, thanks for the continued help. I tried a click handler earlier, and it behaved the same way. Since this is an external page (login.html) loaded by Facebox, I can't seem to debug the script used to fire the code that used to work (or the click handler I tried for that matter). Will Firebug allow me to add break points in external pages loaded via XHR?
David
@David - Yep, though for your click handlers, you may want `.live()` in this case, depending on how they're loaded.
Nick Craver
I will give the .live option a try, but I think Visual Event last told me the event was bound ok. It's just client side validation at this point. new question at http://stackoverflow.com/questions/3868273/jquery-validate-may-have-broken-facebox-pop-up
David