将多个参数发送到PHP(Ajax)

时间:2018-06-15 18:11:12

标签: javascript php jquery ajax

在Ajax上传递或发送多个参数时,我被困在这里。它只在我通过时才有效。这里是Ajax代码:

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

PHP代码:

$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));


}

抱歉我的英语不好:(

1 个答案:

答案 0 :(得分:-1)

您可以序列化表单

{{1}}

您还可以使用表单数据https://stackoverflow.com/a/8244082/3063429