Home > DeveloperSection > Forums > call custom JS function inside jquery/ajax that is defined in an external .js file
Pooja Malohtra
Pooja Malohtra

Total Post:47

Points:331
Posted on    November-23-2014 10:10 PM

 JQuery JavaScript 
Ratings:


 1 Reply(s)
 617  View(s)
Rate this:

only function excute once, then make then whole part of jquery doesn't work. I tried to search but i didn't find right answer. CODE:

<script type="text/javascript" src="Plugs/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="Plugs/jquery.validate.min.js"></script>

<script type="text/javascript" src="Plugs/pop-up.js"></script> <!-- FILE THAT CONTAINS function popup(divNama) { /*instruction*/ } -->

<script type="text/javascript">

$(document).ready(function(){

    //document.write('');

    $("#feeStructure").validate({  

        submitHandler: function(form) {

              popup('popUpDiv'); // custom fn that fire once and make jquery/ajax stop working

            $.post('michangoProc.php', $("#feeStructure").serialize(), function(data) {

                    $('#msgErr').html(data);

        });

        }

    });

        });

        </script>



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    November-24-2014 12:08 AM

You need to change the order that the JavaScript files are loaded.

If you want a function that exists in a file to run in an inline script it must be loaded before your inline script. Your code should look like the below. See that the Plugs/pop-up.js file import now occurs before your inline script

<script type="text/javascript" src="Plugs/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="Plugs/jquery.validate.min.js"></script>

<script type="text/javascript" src="Plugs/pop-up.js"></script> <!-- FILE THAT CONTAINS function popup(divNama) { /*instruction*/ } -->

<script type="text/javascript">

    // $.noConflict();

    $(document).ready(function(){ //$.fn.popup=function(){  } ;

        //document.write('');

        $("#feeStructure").validate({  

            submitHandler: function(form) {

                popup('popUpDiv');

                $.post('michangoProc.php', $("#feeStructure").serialize(), function(data) {

                    $('#msgErr').html(data);

                });

            }

        });

    });

</script>


Don't want to miss updates? Please click the below button!

Follow MindStick