JQuery在Firefox中不起作用,但在Chrome中起作用

dj.*_*vic 4 javascript css firefox jquery google-chrome

我在使用jQuery和Mozzila Firefox时遇到了麻烦.一切都在Chrome中运行得很好,但不知何故Firefox没有看到jQuery.

这就是我调用jQuery的方式

 <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="assets/ico/favicon.png">


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script type="text/javascript" src="assets/bootstrap/js/datepicker.js"></script>
Run Code Online (Sandbox Code Playgroud)

这是它失败的地方(错误是:ReferenceError:$未定义):

 <script>
        function ajax_check(){

            var id = $("#xml_select").val(); // this is the line where I get error

             $.ajax({
                    url: "ajax_check.php?id="+id,
                    success: function(response) {

                        var result = jQuery.parseJSON(response);

                       //console.log( JSON.stringify(result['ncp'].replace('"','')) );

                       var ncp = JSON.stringify(result['ncp']);
                       var id = JSON.stringify(result['id']);


                       $("#racun").val(ncp.substring(1,12));

                       $("#id_podnosilac").val(id.substring(1,5));
                    }, 
                  });

        }
</script>
Run Code Online (Sandbox Code Playgroud)

请帮忙,这可能是什么原因造成的?

Tha*_*nga 5

您将根据加载时间/不同的浏览器随机获得此错误.因为根本原因是你从googleapis加载jquery.min.js.第三方域资源的优先级低于本地域资源.加载本地域资源后,将触发"文档就绪"函数语句.这就是你得到这个错误的原因.

永久解决方案:将jquery.min.js文件放入您的服务器并从您的域中调用它.即使您的页面存在加载时间问题,并且在任何浏览器中,此解决方案仍然有效


dj.*_*vic 2

A.Wolf找到的解决方案

当我按照A.Wolf 的建议发出几个完整请求(ctrl+f5)时,Firefox 开始正常工作。

  • 作为开发人员,我们不能指望网站的用户按 ctrl+f5。大多数用户不知道这一点。我们应该给出永久的解决方案。 (4认同)