I have just stated using XDK and I think its an excellent piece of software. I want to use PHP files in my APP and make calls to an XAMPP database.
I am aware that I have to use jquery/AJAX to connect via PHP files.
My first step is just to get an AJAX call to work with JSON. I keep getting error such as access denied, and 404s for the localhost server im targetting.
I have made my PHP files in the XDK is this going to be okay or do I need to place them elsewhere in my htdocs when working with XAMPP. My issue really is that I do not know what Im fixing. I thought targetting my Xampp URL :localhost -> then path to file would do it.
I also do not know if my jquery is working correctly.
Here is my ajax/jquery/index page :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(e){
e.preventDefault(); // prevent the default action of the click
var fname = $("#name").val();
$.ajax({
type: "GET",
url: 'http://localhost/nearly/nearly/www/php/test.php;',
data: {fname: fname},
dataType: "jsonp",
jsonp: 'callback',
jsonpCallback: 'checkname',
success: function(msg){
msg=alert("hello");
}
});
});
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content">
<form method="get" >
<label for="name">First name:</label>
<input id="name" type="text" name="name" id="name">
<button id="btn1" type="submit">Go</button>
</form>
</div>
<div id="table"></div>
</div>
</body>
</html>
my PHP to handle this is test.php :
<?php
header("Content-Type: application/json");
$fname = $_GET['firstname'];
echo $_GET['checkname'] . '(' . "{'fullname' : '".$fname."'}" . ')';
}
?>
Im not 100% percent on the JSON above I have rarely used this method but have been told its best for mobile applications.
If possible if someone could give some advice on how to set up XDK with Xampp mySQL and let me know if my code above will return anything to my index page so I know its working.
Can I use php files saved inside my "www" project. Can find absolutley no documentation on setting up XAMPP with XDK. I have access to web servers so can put files on there if this is the only way. I have literally spent 2 long nights trying to fix my issues -
Any help is greatly appreciated. For the Xampp question my project is saved in htdocs of my XAMPP