I have a problem. I want to send 3-4 variables from a PHP File to my AJAX request (over json)... and I'm sure that my code is right, it doesn't work. It is doing nothing. If I'm doing just a normal "echo" everything works finde, but json is not working?
Here is my JS-code:
$.ajax({
type: "POST",
url: "test.php",
data: "varA=" + varA + "&varB=" + varB,
dataType: json,
cache: false,
success: function(data1){
alert(data1.b);
if (data1.a == "success"){
alert("OK");
location.href = "index.html";
}
else{
alert("Not OK");
}
}
});
And here is my PHP-code:
...
$qry="SELECT * FROM database1 WHERE varA='".$_POST['varA']."' AND varB='".$_POST['varB']."'";
$result=mysql_query($qry);
if($result) {
if(mysql_num_rows($result) == 1) {
$test = mysql_fetch_assoc($result);
echo json_encode(array('a' => 'success', 'b' => $test['database_entry']));
...
I don't have a clue why this AJAX code would not be fired! Hope you could help me, THANKS!
$_POST['varA']and$_POST['varB']! Please usemysql_real_escape_string($str)in order to prevent executing any SQL commands by a hacker.mysql_*functions, either usemysqli_*or change toPDO, the oldmysql_*functions are going to be deprecated, and they are more vulnerable than usingPDO