Here is my problem:
I am trying to make an Ajax call using jQuery, this calls up the PHP page, the code starts up and echoes OK, if everything is ok, STOP if not.
I am not getting any text back (the first problem), and the real problem is that:
SOMETIMES the request is successful, but ALWAYS returns an error. (even if my sql query on the php page is executed)
Here is the code:
<script>
$("a.confirm").click(function(event){
var id = event.target.id;
$.ajax({
type :"POST",
url :'./PHP/UTILS/confirm.php',
data :{ "id" : id,
},
beforeSend: function(){
alert("in progress");
},
complete: function(){
alert("done");
},
success: function(){
alert("OK");
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err + "\n");
}
});
});
</script>
This is for ajax, now the called page:
<?php
include "./functionsExt.php";
$db = connectToDb('mydb');
$id = $_POST['id'];
$mysql = $db->prepare("UPDATE `test` SET `test_date_p` = CURRENT_TIMESTAMP, `test_status` = '2' WHERE `test_id` = '$id'");
if($mysql->execute()){
echo "OK";
}else{
echo "STOP";
}
?>
thanks for the help
source
share