Intel XDK, AJAX and XAMPP mySQL connection

2019-08-07 00:43发布

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");

0条回答
登录 后发表回答