CALL CUSTOM JS FUNCTION INSIDE JQUERY/AJAX THAT IS DEFINED IN AN EXTERNAL .JS FILE

Pooja Malohtra

Total Post:47

Points:331
Posted by  Pooja Malohtra
 1084  View(s)
Ratings:
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>

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: call custom JS function inside jquery/ajax that is defined in an external .js file

    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>

      Modified On Apr-07-2018 12:42:20 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!