Monday 29 October 2018

php - jquery ajax post doesn't work

I read many posts on this issue but I can not solve the problem.

It seems that ajax() works fine, but the .php file fails to update the SQL database and returns no results to the ajax() function.



This is my code:




var datastring=JSON.stringify(utnew)

$.ajax({
type: "POST",
url: "myulr-php",

data: datastring,
dataType: "json",
success: function(resto){
if (resto=="success"){
$("#pop-confermadatiuser").html("OK");
}else{
$("#pop-confermadatiuser").html("KO");
};
}


});




The php code work, i have try.
this is the code:






header("Access-Control-Allow-Origin: *");
$con = mysqli_connect("sql","xxx","xxx","xxx") or die ("could not connect database");

$ck=1 ;
if(isset($_POST['id']))
{
$id=$_POST['id'];
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$matricola=$_POST['matricola'];

$mail=$_POST['mail'];
$password=$_POST['password'];
$ck=2
$qry="UPDATE user SET nome='".$nome."', cognome='".$cognome."', mail='".$mail."', password='".$password."' where id=".$id." and matricola=".$matricola;

$q=mysqli_query($con,$qry);
if($q) {
echo "success";
} else {
echo "error";

};
mysqli_close($con);
};

if(ck==1){
echo "error2";
};




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...