This code snippet always returns ERROR: 200. It is inserting the data in the database normally, but it returns error in the interface.
$("#registrar").click(function(){
$.ajax({
url : "registra.php",
method: "POST",
dataType : "json",
data : {participante1 : $("#participante1 option:selected").val(),
participante2 : $("#participante2 option:selected").val(),
score1 : $("#score1").val(),
score2 : $("#score2").val()},
success : function(resp){
alert("Registro efetuado com sucesso!");
},
error : function(err){
alert("ERRO: " + err.status);
}
});
});
PHP code:
<?php
$con = pg_connect("host=localhost port=5432 dbname=Jogos user=postgres password=postgres");
$participante1 = $_POST['participante1'];
$participante2 = $_POST['participante2'];
$score1 = $_POST['score1'];
$score2 = $_POST['score2'];
$comando = "INSERT INTO disputas (participante1, participante2, score1, score2)
VALUES ('$participante1', '$participante2', '$score1', '$score2')";
pg_query($con, $comando);
pg_close($con);
?>