Search code examples
phpjqueryajaxhttp-redirectajaxform

.ajaxForm sometimes redirecting


I´m loading my add.php file into a div and in the add.php there is a submit button and some input fields in a form.
Also in the head section there is the following code:

<script>
 $(document).ready(function() {
    $('[name=videoform]').ajaxForm(function() {
       <?php
        //update rows   
       <?

    })
 })

</script>

The add.php gets loaded when I click a button and just a few days ago it started to act weird.
Sometimes it is redirecting to add.php when I click the submit button.
I have another button that will load add.php again, and if I click that afterwards and then try to save, it works most of the time without redirecting

When it does redirect the console writes $(..)ajaxForm not defined, though I load it in the exact same way both of the times.

I´m using this plugin: http://malsup.github.com/jquery.form.js


Solution

  • Got it to work using $('#button').click(function() { instead of $(document).ready
    makes sense :)