我有一个jquery php mysql查询,工作正常,但在我的表单提交之前,我想告诉我的访问者他们会收到多少结果。例如:显示结果(5)。
你能告诉我一个简单的方法吗?
我真的很感激。
编辑:我的ajax如下所示:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
var bedno = document.getElementById('bedno').value;
var district = document.getElementById('district').value;
var loc = document.getElementById('location').value;
var queryString = "?bedno=" + bedno ;
queryString += "&district=" + district + "&location=" + loc;
ajaxRequest.open("GET", "ajax-example.php" +
queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
答案 0 :(得分:0)
您的AJAX
是对的。
在ajax-example.php
文件中,使用您的参数获取结果
并回应结果。
示例
$st = mysqli_query($link, "your query");
$result = mysqli_num_rows($st);
echo $result;