I am trying to send the data I've received using javascript to the localhost but the PHP file doesn't run when I build it as an android application.I've tried running it normally in XAMP before building it and it seems like the PHP connects even tho the data doesn't get sent, however after building it as an ionic android application it doesn't even connect. What is going wrong here?
Index.HTML
<?php
include "main.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- START OF GEOLOCATION -->
<center><div class="round-button"><div class="round-button-circle"><a onclick= "getLocation()" class="round-button">HELP</a></div></div></center>
<p id="demo"></p>
<script src="js/jquery.js"></script>
<script>
var glob_latitude = '';
var glob_longitude = '';
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";}
}
///send to ip
function showPosition(position) {
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
glob_longitude = position.coords.longitude;
glob_latitude = position.coords.latitude;
$.post( "main.php", { latitude: glob_latitude, longitude: glob_longitude } );
}
</script>
<!-- END OF GEOLOCATION -->
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter" background="css/style.css">
</body>
</html>
Main.php
<?php
echo "ok";
//$dbConnection = mysqli_connect("160.153.162.9", "Musab_Rashid" , "zaq123wsx" ,"Musab_Rme");
$dbConnection = mysqli_connect("localhost", "root" , "" ,"info");
echo "connected";
if($dbConnection)
{
echo "connected";
if(isset($_POST['latitude']) and isset($_POST['longitude'])){
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
if($latitude != '' and $longitude != '')
$query = mysqli_query("INSERT INTO info VALUES (NULL, '{$latitude}', '$longitude')");
}
}
else
die();
mysqli_close($dbConnection);
?>