0

I'm stuck here when passing or sending multiple parameters on Ajax. It only works when I pass one. Here the Ajax code:

$.ajax({
                type: "POST",
                url: "dataCartas.php",
                data: {valorXY: valorXY, 
                    CentroX: CentroX},
                success: function(msg){
                    // return value stored in msg variable
                    console.log(valorXY + CentroX)
                }
        });

And the PHP code:

$valorXY = $_POST['valorXY'];
$CentroX = $_POST['CentroX'];

include "configX.php";


if ($conn){

    $sql="EXEC sp_InsertaComID @ComID = '".$valorXY."', @DR = 
'".$CentroX."'";

if ($rs=sqlsrv_query($conn,$sql)){

}else{

echo (print_r(sqlsrv_errors(), true));
}

}else{
die(print_r(sqlsrv_errors(), true));


}

Sorry for my bad english :(

1 Answers1

-1

You can serialize a form

$.ajax({
            type: 'post',
            url: 'include/ajax.php',
            data: $('#form').serialize(),
            success: function (response) {
                // do something
            },
            error: function(jqxhr,textStatus,errorThrown){
                console.log(jqxhr);
                console.log(textStatus);
                console.log(errorThrown);
            }
        }); 

you can also use form data https://stackoverflow.com/a/8244082/3063429

Mike Volmar
  • 1,927
  • 1
  • 22
  • 31