Reload page after posting in iframe (javascript / jquery)

I have a page with iframe. The iframe has a submit button. When I click the submit button, I want to update the parent window. This is what I have done so far and it works (javascript is in the parent window):

var myFrame = $('iframe');
myFrame.load(function() {
myFrame.contents().find('#publish').click(function() {

  myFrame.load(function() {
    location.reload();
  });

});
});

The code is working. But I believe that reloading the iframe is not needed. Is there a better way to detect when a β€œsend” is complete?

(I cannot reload the page with only "onclick" or the relay with any delay. I must be sure that the form submission is completed)

+6
source share
3 answers

, publish , :

$(document).ready(function(){
  $('#publish').live('click', function(e){
     e.preventDefault();
     //Do whatever you want here
   });
});

, live publish .

0

js:

<html>
<script>
 window.parent.document.jQueryFunction();
</script>
</html>

, , ajaxSubmit() jQuery.

$myFrame.contents().find('form').ajaxForm({
  success: function() {
     // update parent
  }
});
0
$("#publish").click(function() {
    $('#inputs').ajaxSubmit({
        success:function(){
            //alert("Reload called");
            parent.location.reload();
        }
    });
 });

It worked.

0
source

All Articles