Errors with jQuery

0

I am making a web page on which I am using jQuery (more specifically this library: link ).

I have this function:

$(document).ready(function(){
        var documento=prueba;
        function obtener_modificacion(){
            $.ajax({                        
                type:"POST",                 
                url:"modificaraprendiz.php",
                success: function(data)             
                {
                    $('#page').html(data);               
                }
            });
        }
       $(document).on("click", "#modificar", function(){
            $.ajax({
                type:"post",
                url:"modificaraprendiz.php",
                data:{doc:documento},
                success: function(data){
                    obtener_modificacion();
                }
            })
        });
    });

It works almost everything correctly: It brings me the page I want, the variables are well defined. The problem is, when I bring the page, the error appears indefinite index (since the page I call, is a query directly).

<?php
  include('conexion.php');
  $doc=$_POST['doc'];
?>

That's how I get it, but it shows me the following error

  

Notice: Undefined index: doc on line 3.

    
asked by Santiago Correa Aguirre Sanmar 26.11.2018 в 17:20
source

2 answers

0

From what I see in the code and in the errors that need to be declared, the variable doc :

 $(document).on("click", "#modificar", function(){
       var doc = "palabra, valor o consulta";
        $.ajax({
            type:"post",
            url:"modificaraprendiz.php",
            data:{doc:documento},
            success: function(data){
                obtener_modificacion();
            }
        })
    });

That's why the error appears. Because the variable was not declared in the sending of it.

    
answered by 26.11.2018 в 17:33
0

you are not sending anything by post method you must use the data method of jquery ajax so that you define $_POST["doc"] with what you want or use the method isset($_POST["doc"]) to validate that it is defined!:

   $(document).ready(function(){
            var documento="prueba";
            var data = {"doc":"lo_que enviaras"};
            function obtener_modificacion(){
                $.ajax({                        
                    type:"POST",
                    data:data,               
                    url:"modificaraprendiz.php",
                    success: function(data)             
                    {
                        $('#page').html(data);               
                    }
                });
            }
           $(document).on("click", "#modificar", function(){
                $.ajax({
                    type:"post",
                    url:"modificaraprendiz.php",
                    data:data ,
                    success: function(data){
                        obtener_modificacion();
                    }
                })
            });
        });
    
answered by 26.11.2018 в 17:29