简体   繁体   中英

Ajax-loaded JQuery issue in IE

I have a website with many products, from within the listing I have a link to a fancybox which opens a full detail of the product (detail.php file)

<a class="fancy fancy'.$_GET['type'].'" href="detail.php?id='.$equip[$c]['equipId'].'">'.$equip[$c]['equipment'].'</a>

The problem is that I have some jquery script inside detail.php, it works fine in every browser except internet explorer, in which I get error $ not defined or JQuery not defined. Above is the jquery code in detail.php

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script type="text/javascript" src="js/vendor/jquery-1.10.1.min.js"><\/script>')</script>


    <script type="text/javascript" src="Resources/Script/jquery.imageLens.js"></script>
            <script type="text/javascript" src="Resources/Script/jquery.nicescroll.js"></script>
        <script>
        window.onload = function(){

            $("#<?php  echo $_GET['id'];?>").imageLens({borderSize: 4, borderColor: "#FFF",lensSize: 200,imageSrc: "<?php  echo "Resources/Image/equipamiento".$row['link'];?>_B.jpg"});
            $(".niceScroll").niceScroll({cursorborderradius:"0px",cursorwidth:4,cursoropacitymin:0.5,cursoropacitymax:0.7,background:"#c9c9c9"});
        }
        $("#catDesc<?php  echo $_GET['id'];?>").click(function(){
            if(!$("#catDesc<?php  echo $_GET['id'];?>").hasClass("active"))
            {
                $("#tech<?php  echo $_GET['id'];?>").fadeOut('fast',function(){
                    $("#desc<?php  echo $_GET['id'];?>").fadeIn('fast')
                    $("#catDesc<?php  echo $_GET['id'];?>").addClass("active")
                    $("#catTech<?php  echo $_GET['id'];?>").removeClass("active")
                })
            }
        })
        $("#catTech<?php  echo $_GET['id'];?>").click(function(){
            if(!$("#catTech<?php  echo $_GET['id'];?>").hasClass("active"))
            {
                $("#desc<?php  echo $_GET['id'];?>").fadeOut('fast',function(){
                    $("#tech<?php  echo $_GET['id'];?>").fadeIn('fast')
                    $("#catTech<?php  echo $_GET['id'];?>").addClass("active")
                    $("#catDesc<?php  echo $_GET['id'];?>").removeClass("active")
                })
            }
        })
        </script>

It looks like your jQuery is undefined because you're referencing a cdn and it is a security issue in some versions of IE. I would recommend downloading jquery and referencing it locally and seeing if that clears up your problem.

Whenever you have $ is not defined , you are not loading the library you are using. That may be caused by IE but I also see you're using "window.onload" and that is "usually" a bad idea (especially for IE) when triggering javascript.

My guess is window.onload behaves differently and possibly reloads the window . Which could be why $ is no longer defined and the library fails to load. Something to keep in mind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM