可靠的选择框不起作用

I'm newbie with AJAX, and I found the code solution for my problem in this page, but I can't make it work.

I need that the input #precio changes when I select an option in select #producto.

I have this code:

<form action="actualizarprod_pr.php" method="post">

    <input type="text" name="producto" value="" placeholder="Producto" list="productolist" />

    <datalist id="productolist">
        <select id="productos" style="display: none;">
            <?php

             $query = "SELECT * FROM lista_precios";

                $query_ej = mysqli_query($conexion, $query);

                while($registro = mysqli_fetch_array($query_ej)){
                    echo "<option value='" . $registro['producto'] .
                         "'</option>";
                }
             ?>
        </select>
    </datalist>

    <input type="text" id="precio" name="precio" placeholder="Precio">
    <input type="submit" name="Actualizar" value="Actualizar">
    <input type="submit" name="Borrar" value ="Borrar">

</form>

Script:

 <script type="text/javascript">
     $(document).ready(function(){

         $("#productos").change(function(){
             var producto=$(this).val();

                 $.ajax({
                     type:"post",
                     url:"cargaselect.php",
                     data:"producto="+producto,
                     success:function(data){
                          $("#precio").val(data);
                     }
                 });

            });

        });
</script>

cargaselect.php:

<?php
    session_start();
    include("conexion.php");

    if(isset($_SESSION["id_usuario"])){ 

        $producto=$_POST["producto"];

        $result = mysqli_query($conexion, 
            "select * FROM lista_precios WHERE producto =". $producto ." ");

        echo $result[precio];

    } else {
        header("location: login.php"); 
    }
?>

This line is not formatted correctly

echo $result[precio];

should be

echo $result['precio'];

What does $result['precio'] return? If its an array of results you might need to use $result[0]['precio'] perhaps instead