我一直试图绕过以下约4-5小时。
基本上,我有一个HTML表单,其中包含从数据库和Submit按钮填充的下拉列表。根据选择的值,我想在表中显示相关细节而不刷新细节。问题是我很难理解jQuery Ajax为什么不做任何事情。
HTML FORM:
<form name="jobIDs" method= "POST">
<label for="valuelist">Job ID </label>
<select name="jobList" id= "jobList">;
<?php
$value= $_POST ["jobList"];
$db->sql('SELECT jobID FROM jobmaster ORDER BY jobID');
$result= $db->getResult();
foreach($result as $output){
echo '<option value="'.$output['jobID'].'">'.$output['jobID'].'</option>';
}
echo "</select>";
?>
<input type="submit" id="jobID-submit" value="Submit">
</form>
<table id="jobDetails">
<thead>
<tr>
<th>Detail</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script type="text/javascript" src="scripts/jobDetails.js"></script>
AJAX
$('input#jobID-submit').on('click',function(){
var jobid= document.getElementById('jobList').value;
// alert (jobid);
function makeAjaxRequest() {
$.ajax({
url: 'ajax/s2_jobDetails.php',
type: 'POST',
data: {jobList: jobid},
success: function(response) {
$('table#jobDetails tbody').html(response);
}
});
}
});
MYSQL / PHP
if (isset($_POST["jobList"])) {
$value= $_POST["jobList"];
.......connection + mysql query...
foreach ($result as $output){
echo '<tr>';
echo '<td> Job ID: </td>';
echo '<td>' . $output['jobID'] . '</td>' ;
echo '</tr><tr>';
echo '<td> Quote ID: </td>' ;
echo '<td>' . $output['quoteID'] . '</td>';
echo '</tr>';
提交按钮元素检查
200- POST - section_2.php 304- GET -jobDetails.js
答案 0 :(得分:0)
您正在向'ajax/s2_jobDetails.php'
发送请求,如果这是此处显示的PHP文件,那么您似乎正在发送HTML内容。请指定您将收到的内容类型,如HTML,JSON等