Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid calling jquery twice

I am using Jquery Form Plugin to submit my form. The head tag of my html file looks like following

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
 then 10 other javascript files

AND Then   
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js">
<script type="text/javascript"> 
       $(document).ready(function() { 
      var options = { 
                       success:       showResponse
                         };
                         $('#myForm').ajaxForm(options); 
        }); 
  </script>         

To see the actual picture of my code please check this http://jsfiddle.net/Xfrms/1/

The problem is even though I call jquery library on the very top of my code, if I don't call the jquery library right before the jquery.form.js plugin then it (jquery.form.js) doesn't work. I have tried to call those 10 other javascript files after the query.form.js plugin calling the jquery library on the very top but in this case the functionality for which the javascript files are being called doesn't work.

After seeing this post, I think calling jquery twice can cause problems.

Could you please tell me what could possibly going wrong in my code and how to avoid having to load jquery right before the the jquery form plugin but still get it working?

Thanks

like image 468
black_belt Avatar asked Jul 24 '12 18:07

black_belt


2 Answers

As I can imagine your problem is that some of the other libraries is using the $ keyword markup to instantiate each calls. If I am correct the just try the following and you will be all set to go..

var $jq = jQuery.noConflict();

Then for all of your jquery calls try use your new markup.. the $jq.

For more detailed info check out this page: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Use the js script reference at the beginning of your page to ensure that all code is loaded properly at start. Moreover it is likely that some error could be populated from loading all scripts.. To check if any errors exist, use some debugging plug in like Firebug.

like image 111
batspy Avatar answered Nov 15 '22 10:11

batspy


Have you tried:

window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')
like image 30
j08691 Avatar answered Nov 15 '22 09:11

j08691