Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking Back after fancyBox AJAX Form Submission

Not sure if this is even possible, but I have a AJAX form like this fiddle:

http://jsfiddle.net/nicorellius/GfeEf/

On my website, it is working fine. I do a simple validation in the form with JavaScript, but if the user gets through the JavaScript, the user is presented with a Campaign Monitor webpage: either saying yay or nay to their validation.

When the user subscribes successfully, if the user clicks back or uses the CM back link, the fancyBox remains with data populated. Based on how I have the script written it should close after submission.

This is Firefox behavior in Linux and Windows. Chrome actually clears the page and removes the fancyBox form.  The AJAX section is here:

$.ajax({
    type       :  "POST",
    cache      :  false,
    url        :  "http://<comapny_name>.createsend.com/a/b/c/abcdef/",
    data       :  $(this).serializeArray(),
    //  I've tried both of these commented out pieces to no avail.
    //beforeSend :  function() {  
                      //$.fancybox.close(true);
                  //},
    //success    :  function(data) {
                      //$.fancybox.close(true);
                  //}
});

So despite adding:

success : function() {
              $.fancybox.close(true);
          }

to the AJAX script, I cannot get it to close after submission.

EDIT

I should note, too, that this phenomenon seems to occur with Firefox, Safari and Opera. Chrome behaves as I would expect (eg, when clicking the back link, I get the fresh page reload). The CM page is using javascript:history.go(-1) to send me back.

like image 505
nicorellius Avatar asked Jan 18 '13 17:01

nicorellius


1 Answers

I have no idea about Campaign Monitor but why not force close your fancybox on document load?

$(document).ready(function(){
  $.fancybox.close(true);
}
like image 145
Ege Akpinar Avatar answered Oct 09 '22 14:10

Ege Akpinar