Monday, October 29, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...