$未在JQuery中定义 [英] $ is not defined in JQuery

查看:70
本文介绍了$未在JQuery中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我向大家展示,我将这段代码放在一个名为Consultas.php的文件中

CONSULTAS.PHP

此文件显示带有数据的表,在名为folio id="'.$row["folio"].'"的列的末尾,当我单击此处时,向我显示并指向VISTAPREVIA.PHP,以获取有关此作品集的更多数据,但在第1页中,它工作得很好,并且现在,当我要转到第2页时,我再次单击并且由于没有显示任何内容而无法工作,该错误告诉我:Uncaught ReferenceError: $ is not defined

<script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            

            });
        });
    </script>
<a href="#" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">CONSULTA DE LA TABLA</h1>
<div class="tabla">
    <table id="registros" class="display" cellspacing="0">
        <thead>
            <tr>
                <th>Folio</th>
                <th>Estatus</th>
                <th>Punto de Venta</th>
                <th>Usuario</th>
                <th>Acciones</th>            
            </tr>
        </thead>        
        <tbody>
            <?php
                while ($row = mysql_fetch_array($consulta)) {
            ?>
                <tr>                            
                    <td><?=$row['folio']?></td>                
                    <td><?=$row['estatus']?></td>                
                    <td><?=$row['punto_venta']?></td>
                    <td><?=$row['usuario']?></td>
                    <td>
                        <?php
                            if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
                                echo '
                                    <center>
                                        <a class="modificar icon-pencil" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                         | 
                                        <a class="detalle icon-eye-plus" href="includes/lightbox.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';                                
                            }else{
                                echo'
                                    <center>                                    
                                        <a class="vistaprevia icon-eye-plus" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';
                            }
                        ?>                        
                    </td>
                </tr>
            <?php
                }
            ?>
        </tbody>
    </table>                 
</div>

VISTAPREVIA.PHP

<?php session_start(); ?>
<head>
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow' rel='stylesheet' type='text/css'>

</head>
<a href="includes/consultas.php" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">ACTUALIZACIÓN DE DATOS</h1>
<!-- <form action="includes/"></form> -->
<?php
    if($_SESSION['permisos'] == 'CALIDAD'){
        include('upRegCal.php');
    }
?>

<form action="includes/edit.php" enctype="multipart/form-data" id="formAct" method="POST" name="enviarForm">
    <?php
        if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
            include('upRegUser.php');
        }

        if($_SESSION['permisos'] == 'ADMINISTRADOR'){
            //include('upRegCal.php');
            echo "Hola Administrador";
        }
    ?>    
</form>

最后

INDEX.PHP
我必须保证这部分是因为我放置了正确的Jquery脚本,但我不知道为什么,我也找不到问题,是的,我使用了Datables脚本

<?php
    session_start();     
?>
<!DOCTYPE html>
<html>
    <head>  
        <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
        <title>Bienvenido</title>
        <script src="js/jquery-1.11.2.js"></script>     
        <script src="js/funciones.js"></script>
        <script src="libs/datatables/media/js/jquery.dataTables.js"></script>
        <script src="libs/datatables/extensions/AutoFill/js/dataTables.autoFill.js"></script>

        <script type='text/javascript' src='js/jquery.simplemodal.js'></script>
        <script type='text/javascript' src='js/basic.js'></script>

        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,300,400,600,700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/normalize.css" type="text/css"/>    
        <link rel="stylesheet" href="css/estilos.css" type="text/css"/>     
        <link rel="stylesheet" href="css/estilosForm.css" type="text/css"/>
        <link type='text/css' href='css/basic.css' rel='stylesheet' media='screen' />       

        <link rel="stylesheet" href="libs/datatables/media/css/jquery.dataTables.css" type="text/css"/>
        <link rel="stylesheet" href="libs/datatables/extensions/AutoFill/css/dataTables.autoFill.css" type="text/css"/>     

    </head>

    <body>
        <div class="fondoHeader"></div>
        <header class="shadow">
            <nav>       
                <?php                               
                if(isset($_SESSION['usuario']))
                    include('includes/btnSiSession.php');                   
                else
                    include('includes/btnNoSession.php');                   
                ?>              
            </nav>          
        </header>       
        <div id='mainContainer'>        
            <?php                           
                include('includes/bienvenido.php');             

                if(isset($_SESSION['usuario'])){
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='none'"; 
                    echo "document.getElementById('login').style.visibility='hidden'"; 
                    echo "</script>";
                }
                else{
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='block'"; 
                    echo "document.getElementById('login').style.visibility='visible'"; 
                    echo "</script>";
                }
            ?>
        </div>
        <div class="clear"></div>
        <footer> 
            <?php
                include('includes/footer.php');
            ?>    
        </footer>
    </body>
</html>

更新 我把这段代码jQuery CDN脚本

<script src="ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            

            });
        });
    </script>

解决方案

consultas.php 中,必须在使用JQuery(<script src="js/jquery-1.11.2.js"></script>)之前,在<script>之前包含JQuery().

在网络中,每个页面都是不同的,那么您必须在每个页面中添加jQuery.

示例

 <script src="js/jquery-1.11.2.js"></script>
<script type="text/javascript">     
        $(document).ready(function() {
        /* ... */
        });
</script>
 

Let me show you all, i put this code in a file called consultas.php

CONSULTAS.PHP

This file shows the table with data, at the end of column called folio id="'.$row["folio"].'" when i clicked there this shows me and towards to VISTAPREVIA.PHP for more data about this folio but in paging #1 it works very well and now when i'm going to paging #2 i clicked again and doesn't work because doesn't show me anything, the error says me: Uncaught ReferenceError: $ is not defined

<script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            

            });
        });
    </script>
<a href="#" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">CONSULTA DE LA TABLA</h1>
<div class="tabla">
    <table id="registros" class="display" cellspacing="0">
        <thead>
            <tr>
                <th>Folio</th>
                <th>Estatus</th>
                <th>Punto de Venta</th>
                <th>Usuario</th>
                <th>Acciones</th>            
            </tr>
        </thead>        
        <tbody>
            <?php
                while ($row = mysql_fetch_array($consulta)) {
            ?>
                <tr>                            
                    <td><?=$row['folio']?></td>                
                    <td><?=$row['estatus']?></td>                
                    <td><?=$row['punto_venta']?></td>
                    <td><?=$row['usuario']?></td>
                    <td>
                        <?php
                            if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
                                echo '
                                    <center>
                                        <a class="modificar icon-pencil" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                         | 
                                        <a class="detalle icon-eye-plus" href="includes/lightbox.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';                                
                            }else{
                                echo'
                                    <center>                                    
                                        <a class="vistaprevia icon-eye-plus" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';
                            }
                        ?>                        
                    </td>
                </tr>
            <?php
                }
            ?>
        </tbody>
    </table>                 
</div>

VISTAPREVIA.PHP

<?php session_start(); ?>
<head>
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow' rel='stylesheet' type='text/css'>

</head>
<a href="includes/consultas.php" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">ACTUALIZACIÓN DE DATOS</h1>
<!-- <form action="includes/"></form> -->
<?php
    if($_SESSION['permisos'] == 'CALIDAD'){
        include('upRegCal.php');
    }
?>

<form action="includes/edit.php" enctype="multipart/form-data" id="formAct" method="POST" name="enviarForm">
    <?php
        if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
            include('upRegUser.php');
        }

        if($_SESSION['permisos'] == 'ADMINISTRADOR'){
            //include('upRegCal.php');
            echo "Hola Administrador";
        }
    ?>    
</form>

last

INDEX.PHP
i have to assure this part because i put the correct Jquery scripts but i don't know why and i couldn't find the problem and yes i use the Datables Scripts

<?php
    session_start();     
?>
<!DOCTYPE html>
<html>
    <head>  
        <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
        <title>Bienvenido</title>
        <script src="js/jquery-1.11.2.js"></script>     
        <script src="js/funciones.js"></script>
        <script src="libs/datatables/media/js/jquery.dataTables.js"></script>
        <script src="libs/datatables/extensions/AutoFill/js/dataTables.autoFill.js"></script>

        <script type='text/javascript' src='js/jquery.simplemodal.js'></script>
        <script type='text/javascript' src='js/basic.js'></script>

        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,300,400,600,700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/normalize.css" type="text/css"/>    
        <link rel="stylesheet" href="css/estilos.css" type="text/css"/>     
        <link rel="stylesheet" href="css/estilosForm.css" type="text/css"/>
        <link type='text/css' href='css/basic.css' rel='stylesheet' media='screen' />       

        <link rel="stylesheet" href="libs/datatables/media/css/jquery.dataTables.css" type="text/css"/>
        <link rel="stylesheet" href="libs/datatables/extensions/AutoFill/css/dataTables.autoFill.css" type="text/css"/>     

    </head>

    <body>
        <div class="fondoHeader"></div>
        <header class="shadow">
            <nav>       
                <?php                               
                if(isset($_SESSION['usuario']))
                    include('includes/btnSiSession.php');                   
                else
                    include('includes/btnNoSession.php');                   
                ?>              
            </nav>          
        </header>       
        <div id='mainContainer'>        
            <?php                           
                include('includes/bienvenido.php');             

                if(isset($_SESSION['usuario'])){
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='none'"; 
                    echo "document.getElementById('login').style.visibility='hidden'"; 
                    echo "</script>";
                }
                else{
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='block'"; 
                    echo "document.getElementById('login').style.visibility='visible'"; 
                    echo "</script>";
                }
            ?>
        </div>
        <div class="clear"></div>
        <footer> 
            <?php
                include('includes/footer.php');
            ?>    
        </footer>
    </body>
</html>

UPDATE i put this code jQuery CDN script

<script src="ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            

            });
        });
    </script>

解决方案

In consultas.php, you must include JQuery (<script src="js/jquery-1.11.2.js"></script>) before using it, before your <script>.

In web, each page is different, then you must add jQuery in each one.

example

<script src="js/jquery-1.11.2.js"></script>
<script type="text/javascript">     
        $(document).ready(function() {
        /* ... */
        });
</script>

这篇关于$未在JQuery中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆