在表单加载和单击提交按钮后调用php脚本Ajax方式

时间:2016-11-20 04:42:55

标签: javascript ajax

我有一个PHP表单,并在单击页面时加载。 php表单有多个输入,单击提交按钮时需要更新tABLE。  我需要转到Ajax方式,但我不知道如何在表单操作完成后调用php脚本来重新加载表。任何指针都会有所帮助。

<form target="iframe_b" action="/php_src/srcsendMTdata.php" method="POST"
        echo "sending data">
  <fieldset>
Select SCEF:<br>
    <?php
    $dbuser = 'root';
    $dbpass = 'xxxx';
    $conn   = mysql_connect($dbhost, $dbuser, $dbpass);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("ApplicationServer") or die(mysql_error());
    // Get all the data from the "example" table
    $result = mysql_query("SELECT SCEF_NAME  FROM SCEF_DETAILS") or die(mysql_error());
   echo "<select name='SCEF_Name' id='id_scefName'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['SCEF_NAME'] . "'>" . $row['SCEF_NAME'] . "</option>";
}
echo "</select>";
   ?>
<br><br>
<div>
<select name='takeaction' id="Actions" >
<option class='head'>Select Action</option>
<option value='Activate Devices'>Activate Devices</option>
<option value='Send MTData'>Send MTData</option>
<option value='Get MTData'>Get MTData</option>
</select>
<input type="submit" value="SUBMIT" name="submit_button">
<br><br>
<input type="text" id="id_mt_data" name="MT_data" value="MT DATA"  style="display: none;" />
 </div>
<br><br>
<table border="1">
<tr>
 <th><input type="checkbox" id="selectall"/></th>
        <th>External ID</th>
        <th>Status</th>
</tr>
// This portion needs to be dynamic.(Below needs to be separate PHP script called via Ajax when the form is loaded and when the submit
button is pressed
<?php
$dbhost = 'localhost:3036';
    $dbuser = 'root';
    $dbpass = 'xxx';
    $conn   = mysql_connect($dbhost, $dbuser, $dbpass);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("ApplicationServer") or die(mysql_error());
    // Get all the data from the "example" table
    $result = mysql_query("SELECT EXTERNAL_ID,CONNECTION_STATUS FROM DEVICE_DETAILS") or die(mysql_error());
   while ($row = mysql_fetch_array($result)) {
   $extID =  $row['EXTERNAL_ID'];
   $conStatus = $row['CONNECTION_STATUS'];
       echo "</tr><tr>";
       echo "</td><td>";
       echo "<input type=\"checkbox\" class=\"case\"  name=\"checkBox[".$extID."]\" />";
       echo "</td><td>";
       echo "<input type=\"text\" class=\"classextID\"  value=\"$extID\" name=\"textExID[".$extID."]\" />";
       echo "</td><td>";
       echo "<input type=\"text\" class=\"classConnection\"  value=\"$conStatus\" name=\"textcon[".$extID."]\" />";

 }
?>

</table>
</fieldset>
</form>

0 个答案:

没有答案