开发者

Submitting form, with JavaScript with no Submit

I have a script, that does: 1. Check when iframe is 100% loaded. 2. Then when iframe is loaded, a progress bar/countdown appear. 3. When the countdown hits 0, I want to do a $_POST of the current page, but I want to do it without a submit button or anything else.

Here is my code:

// on document load:
$(function() {
   // set "waiting" message:
   $("#loadingStatus").html("Waiting for your advertisements to load...");

   // on iframe load:
   $('#iFrame').load(function() {

       $("#loadingStatus").html($("#isDone").html());



   });
});

$(function count() {
   var seconds = <?php echo $exposure[$r['exposure']]; ?>;
   setTimeout(updateCountdown, 1000);

   function updateCountdown() {
      seconds--;
      if (seconds > 0) {
         $("#countdown").text("You have " 开发者_运维问答+ seconds + " seconds remaining");
         setTimeout(updateCountdown, 1000);
      } else {
         submitForm();
      }
   }
});

        $(function submitForm() {
            $('form').submit(function(){
                $('#status').hide();
                $.post(
                    '?i=v&p=k&key=DSF79SADFHSA7D9FGSAD097FSAD7F9779ASDFGS9', 
                    $('form').serialize(),
                    function (data) {
                        proccessData(data);
                    }
                );
                return false;    
            });
        });

        function proccessData (data) {
            $('#status').hide().html('');

            if(data=='success'){
                $('form').fadeOut();
                $('#status').addClass('noti-success').html('You have successfully viewed this advertisement.').slideDown();
                redirect("?i=l");
            }
            else {
                $('#status').addClass('noti-error').html(data).fadeIn();
            }
        }


just do a document.forms.formName.submit()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜