I have to get my smartphone-application to work until tomorrow and after hours of work I can't solve it on my own.
Important part of the PHP:
$sql = "SELECT `player_id`, `intro`, `level1`, `level2`, `level3`, `sectask1`, `sectask2`, `sectask3` FROM `matrix` WHERE `matrix`.`player_id` = '$id';";
$result = $conn->query($sql);
$results = array();
while ($row = mysqli_fetch_assoc($result)) {
$results[] = $row;
};
$json = json_encode( $results);
header("Content-type: application/json");
echo( $_GET['callback'] . ' (' . $json . ');' );
?>
My Javascript Function:
$(document).ready(function() {
$(".slogan").click( function(){
console.log("EnterMatrix");
$.ajax({type: "GET",
url: 'http://192.168.141.98/getmatrix.php',
dataType: "jsonp",
crossDomain: true,
success: function(data) {
console.log("intro");
var users=JSON.parse(data);
console.log(data);
var intro = users[0].intro;
var level1 = users[0].level1;
var level2 = users[0].level2;
var level3 = users[0].level3;
var sectask1 = users[0].sectask1;
var sectask2 = users[0].sectask2;
var sectask3 = users[0].sectask3;
if(intro==0){
console.log("clicked2");
$("#matrix_introduction").show(300);}
else{
$("#matrix_introduction2").show(300);}
},
error: function(jqXHR, textStatus, errorThrown) {
alert('error ' + textStatus + " " + errorThrown);
}
});
});
});
What is Wrong - I am thankful for every hint!
I already tried a hella lot of solutions! Maybe it is something obvious?
Thanks :)
$json = json_encode( $results);
header("Content-type: application/json");
echo( $_GET['callback'] . ' (' . $json . ');' );
replace this code with
$json = json_encode( $results);
echo $json;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.