Pass several variables with javascript from a view to a function in the controller

0

Hello stack overflow friends in Spanish, my question is if you can help me to pass more than one variable in the following code, I will be very grateful

<script type="text/javascript">
	function PagarCuotaCuenta(cuotas,importe,id_cuentacorriente){

		var cuotas = cuotas;
		var importe = importe;
		var id_cuentacorriente = id_cuentacorriente;

		document.location.href = "<?php echo base_url() . 'clientes/C_Cliente/PagarCuentaCorriente/' ?>" + importe;
		
	}
</script>
    
asked by Fede 09.10.2018 в 22:42
source

2 answers

0

What you can do then is something like this:

var uri = "http://localhost:8080/clientes/C_Cliente/PagarCuentaCorriente.php?cuotas=" + cuotas + "&importe=" + importe + "&cuentacorriente=" + id_cuentacorriente;
window.location.href = encodeURIComponent(uri); 

In particular I do not like to use php in javascript, I better use the path to my server, in the example I point to my localhost and the files to which I will send my request.

Also use encodeURIComponent, this function encodes special characters.

And with your example, I think it would be something like this:

document.location.href = "<?php echo base_url() . 'clientes/C_Cliente/PagarCuentaCorriente.php?cuotas=" + cuotas + "&importe=" + importe + "&cuentacorriente=" + id_cuentacorriente +"'";
    
answered by 10.10.2018 в 06:55
0

So that you do not complicate concatenating php variables with javascript variables, declare baseurl variable as a javascript variable and then concatenate it.

<script type="text/javascript">
    function PagarCuotaCuenta(cuotas,importe,id_cuentacorriente){
        var baseurl = '<?php echo base_url(); ?>';
        var cuotas = cuotas;
        var importe = importe;
        var id_cuentacorriente = id_cuentacorriente;

        document.location.href = base_url+'clientes/C_Cliente/PagarCuentaCorriente/' + importe;

    }
</script>
    
answered by 10.10.2018 в 09:29