1

I am new to both Intel XDK and jquery mobile. I know I want to use a database in my app so have gone about making a simple page that queries my database on XAMPP. The Basic page follows:

 <!DOCTYPE html>
<html>
<head>
<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>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("tap","#name1",(function(e){
       e.preventDefault(); // prevent the default action of the click
           var vname = $("#name").val();
           $.post("test.php", {name:vname}, function(response, status) { // POST instead of GET
               // never use alert() for troubleshooting
               // output for AJAX must be in the callback for the AJAX function
               //console.log("recieved data-------*\n\nResponse : " + response +"\n\nStatus : " + status);
               $('#table').html(response); // put response in div
        });
    });


   </script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>The tap Event</h1>
  </div>

  <div data-role="main" class="ui-content">
    <form method="post">
      <select name="name">
        <option value="Gammaplex">Gammaplex</option>
          <option value="Specifics">Specifics</option>
          <option value="Vigam">Vigam</option>


        </select>
      <button id="name1" type="submit">GO</button></form>
  </div>
<div id="table"></div>
  <div data-role="footer">
    <h1>Footer Text</h1>
  </div>
</div> 

</body>
</html>

The page layout is straight off of W3C schools. The query Im running on the dtabase is a known script that works on a PHP application I have. I have added it for completeness: TEST.PHP

<?php
include 'config.php';

$batchtype2 =($_POST['name']);


$batchtype2 = mysqli_real_escape_string($con,$batchtype2);
$sql = "SELECT * FROM script WHERE scriptname  ='".$batchtype2."' ";       


$result = mysqli_query($con,$sql);

$count=mysqli_num_rows($result);

if($count==0 ){


 echo "</br></br></br></br></br></br></br><p> No Matching results found</p>";
}else{
    while($row = mysqli_fetch_array($result)) {



       echo " <form id='addgo' method='post'><label>Batch Number :</label><input id='gambana' name='gambana'>";
  echo " <label>Planned Start Time : </label>"
       . "<p><label>Hours /</label><label style='margin-left:2%;'>Mins</label></p><select id='pbstarti' name='pbstarti'>"
          . "<option value='00'>00</option>"
          . "<option value='01'>01</option>"
          . "<option value='02'>02</option>"
          . "<option value='03'>03</option>"
          . "<option value='04'>04</option>"
          . "<option value='05'>05</option>"
          . "<option value='06'>06</option>"
          . "<option value='07'>07</option>"
          . "<option value='08'>08</option>"
          . "<option value='09'>09</option>"
          . "<option value='10'>10</option>"
          . "<option value='11'>11</option>"
          . "<option value='12'>12</option>"
          . "<option value='13'>13</option>"
          . "<option value='14'>14</option>"
          . "<option value='15'>15</option>"
          . "<option value='16'>16</option>"
          . "<option value='17'>17</option>"
          . "<option value='18'>18</option>"
          . "<option value='19'>19</option>"
          . "<option value='20'>20</option>"
          . "<option value='21'>21</option>"
          . "<option value='22'>22</option>"
          . "<option value='23'>23</option>"

          . "</select><select id='endtime' style='margin-left:2%;' name='endtime'>"
   . "<option value='00'>00</option>"
          . "<option value='05'>05</option>"
          . "<option value='10'>10</option>"
          . "<option value='15'>15</option>"
          . "<option value='20'>20</option>"
          . "<option value='25'>25</option>"
          . "<option value='30'>30</option>"
          . "<option value='35'>35</option>"
          . "<option value='40'>40</option>"
          . "<option value='45'>45</option>"
          . "<option value='50'>50</option>"
          . "<option value='55'>55</option>"
          . "</select>";

 echo "     <label>      Planned Start Date:</label> <input name='datepicker1' id='datepicker1' readonly='readonly'>";

   echo "        <input id='scriptp' name='scriptp' type ='hidden' value='0'>";
      echo "       <input id='batchtype' name='batchtype' type ='hidden' value='".$row['scriptname']."'>";
      echo "<input id='scripthours' name = 'scripthours'; type='hidden' value='".$row['scripthours']."'>";
          echo "<input id='formulation' name = 'formulation'; type='hidden' value='".$row['formulation']."'>";

         echo " <input id='adddate' type='submit' value='Add ".$row['scriptname']." batch' class='btn btn-primary'></form>";
       echo "  ";

 }
}
mysqli_close($con);
?>

When I run the file and log it in the console I get a cant find resource error. For my test.PHP file.

my file structure for the project is:

www (Top Level)

index.html ---- PHP folder (second Level)

config.php ----- test.php (third level)

I have tried / slashes infront absolute URLs with no success. I then start to think that it might be the JQM that is written incorrectly.

The project is placed in the htdocs folder of my XAMPP.

is there a method to follow when adding resources to XDK and Ripple?

Many thanks for any help recieved.

Finally here is my config file just in case:

<?php



$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test3"; // Database name 

// Connect to server and select databse.
$con = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
mysqli_select_db($con,"$db_name")or die("cannot select DB");
Fintan Creaven
  • 250
  • 2
  • 17
  • 1
    Add-- header('Access-Control-Allow-Origin: *'); -- as the 1st line in your php script files. Then find your WAN IP address (google = whats my wan ip) from your XAMP server/pc. Get the address and change ($.post("test.php") to ($.post("http://mywanIP/phpfolder/test.php"). Login on your router, under Firewall - Virtual Servers. You may have a drop down menu there so choose (WEB SERVER/HTTP) and it will fil in the blanks for you so you can add the last digits of the XAMPS server ip -- if you dont know the local XAMP IP, open a console and type -- ifconfig (on mac, linux) -- ipconfig (windows) – Tasos May 19 '15 at 01:21
  • @Tasos Anasastasiou Thanks for your comment I will give this a go tonight. Gave up the ghost last night. In the past with netbeans, joomla and standard phonegap/Cordova installs simply placing the project in the htdocs has always worked. Hopefully this solves it. – Fintan Creaven May 19 '15 at 06:49
  • 1
    them for faster access, and server scripts reside on the web server so you need a domain name or a wan ip to access them on the server. the header('Access-Control-Allow-Origin: *'); for the php scripts can help with over the net access issues although there are other ways to achieve that – Tasos May 19 '15 at 14:38
  • @TasosAnastasiou hello, I tried your method - I got lost on the Firewall-virtual servers part. I added my wan from google and made attempts and used 127.0.01 and localhost directing straight to the file. Depending how I typed the url I either got a 404 or a access denied in my logs – Fintan Creaven May 19 '15 at 23:16
  • 1
    127.0.01 is the loopback adress of your server. whats the machines IP adress?? eg 192.168.1.10 -- this is the address you need to insert on the router. Once you enabled PORT 80 to direct web traffic to the webservers IP address the Router should be able to send HTTP requests to the PC that has the web server on. so when you type the WAN IP on a browser from anywere in the world you should access your website and you PHP scripts in your JS files using the WAN address – Tasos May 19 '15 at 23:27
  • @TasosAnastasiou I have both my wan IP and maching IP from google if my wan ip was 108.154.25.237 are you saying XAMPP is running on port 80, do I implement like : 108.154.25.237:80 – Fintan Creaven May 19 '15 at 23:29
  • 1
    Your WAN IP and your WEB SERVERS IP are different address. The WAN is Puplic and the WEBSERVERS is private. You need to google for your system, windows or mac on how to find my local IP address. This is the one you need to insert on the router in virtual servers --- http://lifehacker.com/5833108/how-to-find-your-local-and-external-ip-address – Tasos May 19 '15 at 23:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78261/discussion-between-fintan-creaven-and-tasos-anastasiou). – Fintan Creaven May 19 '15 at 23:46

0 Answers0