Search code examples
jqueryformwizardjquery-form-wizard

Issue with the load function in jQuery


I have 2 files: users.php and form.php.

I use the file users.php to show the users from a database. I am also using the jQuery function load() to load the login form from form.php.

I put the jQuery library in the header of login.php . In form.php I have some jQuery functions so I have to put the jQuery library in it also.

The problem is when I use the $("#loginForm").load("form.php") the jQuery get all the libraries of form.php

form.php :

<script src="js/jquery-1.8.3.js"></script> 

<script src="js/ui/jquery-ui-1.9.2.custom.js"></script>
<!-- Jquery form wizard -->
<script src="js/formWizard/jquery.form.js"></script>    
<script src="js/formWizard/jquery.validate.js"></script>    
<script src="js/formWizard/bbq.js"></script>  
<script src="js/formWizard/jquery.form.wizard.js"></script>
<form method="post" >
    ...
</form>

user.php

<div id="loginForm"> 
</div>

And in the header of user.php there are these scripts files above


Solution

  • I'm not exactly clear on your problem but it sounds like your jQuery libraries are loading in twice. Once from user.php and once from form.php

    To stop this happening, you could try extracting the libraries from user.php and form.php to one common header file (header.php). then use

    require_once('header.php');
    

    function to ensure the file is loaded only once.