0

I have two scripts. One is for jquery forms and the other to refresh a div at intervals.

Without the refresh script the jquery posts work. When I add the refresh script, the forms submit the default way but the refresh works. I assume the solution is to combine them. My efforts failed. Help!

UPDATE: Each script works as long as the other is not in the code, too. Attempts to merge also fail. I've added the <form> for reference. To clarify, when both are present or combined the default /GET occurs instead of the ajax executing. The refresh always works. I've confirmed submitting the form before the refresh occurs makes no difference.

UPDATE 2: If I move the form submit code into the DIV that is refreshed I can run it properly BUT only until the refresh occurs. After the first ajax refresh the form begins submitting traditionally.

<script>
  $(document).ready(function() {
    $(".col-xs-4").load(\"statisticsDiv");
    var refreshId = setInterval(function() {
      $(".col-xs-4").load('/statisticsDiv?randval='+ Math.random());
    }, 10000);
    $.ajaxSetup({ cache: false });
  });
</script>")); 
 
<script>
  $(document).ready(function() {
    $('#myForm').ajaxForm(function() {
    });
  });
</script>
<form id="myForm" action="http://192.168.1.150:2560/" method="get">
<input type="hidden" name="cleaner" value="on" /> 
<input type="submit" value="Toggle" /> 
</form>

SOLVED: Added this to rebind the element returned after the DIV refresh. Might not be correct way but it works. Refining suggestions?

    $(document).ajaxStop(function() { 
      $('#myForm').ajaxForm(function() {
      });
    });
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
dotJake
  • 1
  • 1

1 Answers1

0

...like this?

<script>
  $(document).ready(function() {
    $(".col-xs-4").load(\"statisticsDiv");

    var refreshId = setInterval(function() {
        $(".col-xs-4").load('/statisticsDiv?randval='+ Math.random());
    }, 10000);

    $.ajaxSetup({ cache: false });
    $('#myForm').ajaxForm();
  });
</script> 
Tyler Roper
  • 21,445
  • 6
  • 33
  • 56