我正在构建一个页面,在选择了两个日期和几个下拉列表后,AJAX POST执行SQL:
window.onload = function(){
Search();
}function Search(){
var CIAttributeCompletenessCITypeID = $('#CIType').val();
var CIAttributeCompletenessCISubTypeID = $('#CISubType').val();
var CIAttributeCompletenessCIAttributeID = $('#CIAttribute').val();
var CIAttributeCompletenessStartDate = $('#start').val();
var CIAttributeCompletenessEndDate = $('#end').val();
var CIAttributeCompleteness = {CIAttributeCompletenessCITypeID,CIAttributeCompletenessCISubTypeID,CIAttributeCompletenessCIAttributeID,CIAttributeCompletenessStartDate,CIAttributeCompletenessEndDate};
$.ajax({
type:'POST',
url:'/ITSMIS/getData/CIAttributes.php',
data:CIAttributeCompleteness,
success:function(html){
$('#CIAttributeCompleteness').html(html);
$(".data-table").DataTable();
}
})
在查询返回结果后,PHP会根据每一行向页面写入某些字段。
if(!empty($_POST["CIAttributeCompletenessCITypeID"]) && !empty($_POST["CIAttributeCompletenessCISubTypeID"]) && !empty($_POST["CIAttributeCompletenessCIAttributeID"])){
$sql = "SELECT CIAttributeCompleteness.CIAttributeCompletenessPercentage, CIAttributeCompleteness.CIAttributeCompletenessMissing, CIAttributeCompleteness.CIAttributeCompletenessCompleted, CIAttributeCompleteness.CIAttributeCompletenessTotal, CIAttributeCompleteness.CIAttributeCompletenessDate, CIType.CITypeTitle AS CIAttributeCompletenessCITypeTitle, CISubType.CISubTypeTitle AS CIAttributeCompletenessCISubTypeTitle, CIAttribute.CIAttributeTitle AS CIAttributeCompletenessCIAttributeTitle FROM CIAttributeCompleteness INNER JOIN CIType ON (CIType.CITypeID = CIAttributeCompleteness.CIAttributeCompletenessCITypeID) INNER JOIN CISubType ON (CISubType.CISubTypeID = CIAttributeCompleteness.CIAttributeCompletenessCISubTypeID) INNER JOIN CIAttribute ON (CIAttribute.CIAttributeID = CIAttributeCompleteness.CIAttributeCompletenessCIAttributeID) WHERE CIAttributeCompleteness.CIAttributeCompletenessCITypeID = ".$_POST['CIAttributeCompletenessCITypeID']." AND CIAttributeCompleteness.CIAttributeCompletenessCISubTypeID = ".$_POST['CIAttributeCompletenessCISubTypeID']." AND CIAttributeCompleteness.CIAttributeCompletenessCIAttributeID = ".$_POST['CIAttributeCompletenessCIAttributeID']." AND CIAttributeCompleteness.CIAttributeCompletenessDate BETWEEN '".$_POST['CIAttributeCompletenessStartDate']."' AND '".$_POST['CIAttributeCompletenessEndDate']."'";$stmt = sqlsrv_query($conn, $sql);
while($obj = sqlsrv_fetch_object($stmt)){
echo "
<tr>
<td>".date_format($obj->CIAttributeCompletenessDate, 'd/m/Y')."</td>
<td>".$obj->CIAttributeCompletenessCITypeTitle."</td>
<td>".$obj->CIAttributeCompletenessCISubTypeTitle."</td>
<td>".$obj->CIAttributeCompletenessCIAttributeTitle."</td>
<td>".$obj->CIAttributeCompletenessPercentage."</td>
<td>".$obj->CIAttributeCompletenessMissing."</td>
<td>".$obj->CIAttributeCompletenessCompleted."</td>
<td>".$obj->CIAttributeCompletenessTotal."</td>
</tr>";
}
这将数据输出到页面上。但是,除了发布的数据/ HTML元素之外,没有任何JavaScript可用。
这只是我尝试过的,它应该隐藏任何不符合搜索条件输入的行到文本框中:
var $rows = $('.data-table tr');
$('#search-y').keyup(function() {
var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function() {
text = $(this).text().replace(/\s+/g, ' ');
return !reg.test(text);
}).hide();
});
它基本上就像任何JavaScript都不会识别页面上有HTML输出。
答案 0 :(得分:0)
把你希望在Ajax的成功部分运行的javascript。 dom应该拿起html然后。 - Mueyiwa Moses Ikomi