繁体   English   中英

单击按钮时Javascript无法执行PHP文件

[英]Javascript not executing PHP file when a button is clicked

我有一个按钮,该按钮使用函数进行一些计算,然后将数据插入表中。 一切正常,但现在不起作用,我也不知道为什么。 我希望有人能帮助我。 一切对我来说似乎还可以,我不知道该怎么办。

这是按钮代码:

<button type="button" name="btnAgregarProducto" class="btn btn-xs btn-primary" id="command-add" onclick="rowFunction('dgvDetalleFactura')" data-row-id="0">
                            <span class="glyphicon glyphicon-plus"></span> Producto</button>

这是JS代码:

<script>
    /*Insertar productos en el detalle*/
     function rowFunction(Tabla) {

        /*Ir a factura, calcular todo y luego traerlo y meterlo en la tabla*/

        $.ajax({
                        url: 'Logica/Factura.php',
                        type: 'post',
                        data: 
                        {
                           btnAgregarProducto:'AgregarProducto', 
                           PV:document.getElementById('PrecioVenta').value,
                           IV:document.getElementById('IV').value,
                           Des:document.getElementById('Descuento').value,
                           Cant:document.getElementById('Cantidad').value,
                           IDp:document.getElementById("IDProducto").value,
                           NombreP:document.getElementById("NombreProducto").value;
                           UM:document.getElementById("UnidadMedida").value;

                        },
                        dataType: 'json',
                        success:function(response){

                            var len = response.length;

                            if(len > 0){
                                var IdProducto = response[0]['IDProducto'];
                                var Nombrep = response[0]['NombreProducto'];
                                var PV = response[0]['PrecioVenta'];
                                var iv = response[0]['Impuesto'];
                                var Desc = response[0]['Descuento'];
                                var UM = response[0]['UM'];

                                var a = document.getElementById(Tabla).insertRow(1);

                                var Codigo = a.insertCell(0);
                                var Producto = a.insertCell(1);
                                var Cantidad = a.insertCell(2);
                                var Precio = a.insertCell(3);
                                var Medida = a.insertCell(4);
                                var Impuesto = a.insertCell(5);
                                var Descuento = a.insertCell(6);
                                var Subtotal = a.insertCell(7);
                                var Total = a.insertCell(8);
                                var BotonBorrar = a.insertCell(9);

                                Codigo.innerHTML =IdProducto;   
                                Producto.innerHTML =Nombrep;
                                Cantidad.innerHTML =document.getElementById("Cantidad").value;
                                Precio.innerHTML =PV;
                                Medida.innerHTML =document.getElementById("UnidadMedida").value;
                                Impuesto.innerHTML =document.getElementById("IV").value;
                                Descuento.innerHTML =document.getElementById("Descuento").value;
                                Subtotal.innerHTML = 'Subtotal';
                                Total.innerHTML = "Total";

                                BotonBorrar.innerHTML='<button class="btn btn-primary btn-xs my-xs-btn" type="button" onClick="borrarFila(this)" >'
+ '<span class="glyphicon glyphicon-remove"></span>Borrar</button>';
                            }

                        }
                    });

                    return false;
     }
  </script>

PHP文件代码:

  <?php 
session_start();

require ("../Conexion/Conexion.php");

//Verificar que el usuario haya pulsado el boton de agregar producto
if(isset($_POST['btnAgregarProducto']))
{
    $IDProducto=$_POST['IDp'];
    $NombreProducto=$_POST['NombreP'];
    $PrecioVentaSinIV=$_POST['PV'];
    $ImpuestoVenta=$_POST['IV'];
    $Descuento=$_POST['Des'];
    $Cantidad=$_POST['Cant'];
    $UnidadMedida=$_POST['UM'];

    if($ImpuestoVenta==0) /*Sino Tiene Impuesto*/
    {
        $MontoExento=$PrecioVentaSinIV*$Cantidad;  /*Precio sin impuesto x Cantidad sino tiene impuesto*/
        $MontoGravado=0; 

    }
    else /*Si Tiene Impuesto*/
    {
        $MontoExento=0;
        $MontoGravado=$PrecioVentaSinIV*$Cantidad;  /*Precio sin impuesto x Cantidad si tiene impuesto*/
    }

    if($UnidadMedida=='sp' AND $ImpuestoVenta==0)
    {
        $MontoSExento=$PrecioVentaSinIV*$Cantidad; /*Precio sin impuesto x Cantidad*/
        $MontoSGravado=0;
    }
    else
    {
        $MontoSExento=0/*Precio con impuesto x Cantidad*/
        $MontoSGravado=$PrecioVentaSinIV*$Cantidad;
    }       

    $MontoIV=($PrecioVentaSinIV*$Cantidad)*$Descuento)*$ImpuestoVenta; /*((Precio sin impuesto x Cantidad)*Descuento) x IV*/
    $MontoOtroI=0;/*se va a cambiar mas adelante*/
    $MontoDescuento=($PrecioVentaSinIV*$Cantidad)*$Descuento);/*(Precio sin impuesto x Cantidad)*Descuento*/


    $SubtotalL=($PrecioVentaSinIV*$Cantidad);/*Precio sin impuesto x Cantidad*/
    $TotalL=$SubtotalL-$MontoDescuento+$MontoIV;/*Subtotal-Descuento+Impuesto*/

    $users_arr[] = array("IDProducto" => $IDProducto, "NombreProducto" => $NombreProducto,"PrecioVentaConIV" => $, "Impuesto" =>$ImpuestoVenta, "Descuento" =>$Descuento, "UM"=>$UnidadMedida,"Cantidad"=>$Cantidad);
    }

    // encoding array to json format
    echo json_encode($users_arr);
    exit;
}

?>

。NombreP:的document.getElementById( “NombreProducto”)值; 。UM:的document.getElementById( “UnidadMedida”)值;

应该有,没有; 在这些行的末尾。

您是否在src js中更改(添加或删除了)任何内容? 例如<script src="assets/respond/respond.js"></script>

当我用Java语言“停止Workind”时,最常见的问题是这些更改。 如果您这样做,请撤消...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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