我想尝试从 ajax 搜索数据,我在 ajax 中发送数据和页码以将数据调用到特定页面,但它无法正常工作,请告诉我一个解决方案。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Member Directory</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.js"></script>
<script>
function getdata(cat,page)
{
if(cat.length>0)
{
$.ajax({
type: "GET",
url: "getdetail.php",
data: "from="+cat+ "&page="+page ,
success: function(response){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
document.getElementById("show1").innerHTML = response;
}
});
}
}
$(document).ready(function(){
$("#searchform").hide();
$("#addvance").click(function(){
$("#searchform").slideToggle(200);
});
});
function search(page) {
$.ajax({
type: "POST",
url: "searchform.php",
data: "page="+ page + "&gender=" + document.getElementById('gender').value + "&gautra=" +document.getElementById('gautra').value+
"&fname=" +document.getElementById('fname').value + "&lname=" +document.getElementById('lname').value+
"&state=" +document.getElementById('state').value + "&city=" +document.getElementById('city').value+
"&birth_place=" +document.getElementById('birth_place').value+ "&mobile=" +document.getElementById('mobile').value ,
success: function(response){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
document.getElementById("show1").innerHTML = response;
}
});
});
</script>
<style type="text/css">
.DirectoryLinkTable tr td input[type=button]{
background: none;
border: none;
padding: 0px;
margin-right: 5px;
border-right: 1px solid #333;
padding-right: 5px;
cursor:pointer;
float:left;
font-size:12px;
line-height:20px;
}
.DirectoryLinkTable tr td input[type=button].AdvanceSearch, .AdvanceSearch{
float:right;
border:1px solid #333;
padding:0px 3px;
background:#feef8d;
}
</style>
</head>
<body>
<div>
<table class="DirectoryLinkTable"><tr>
<td>
<input type="button" value="All" class="button" >
<input type="button" value="A" onclick="getdata(this.value,'1')">
<input type="button" value="B" onclick="getdata(this.value,'1')">
<input type="button" value="C" onclick="getdata(this.value,'1')">
<input type="button" value="D" onclick="getdata(this.value,'1')">
<input type="button" value="E" onclick="getdata(this.value,'1')">
<input type="button" value="F" onclick="getdata(this.value,'1')">
<input type="button" value="G" onclick="getdata(this.value,'1')">
<input type="button" value="H" onclick="getdata(this.value,'1')">
<input type="button" value="I" onclick="getdata(this.value,'1')">
<input type="button" value="J" onclick="getdata(this.value,'1')">
<input type="button" value="K" onclick="getdata(this.value,'1')">
<input type="button" value="L" onclick="getdata(this.value,'1')">
<input type="button" value="M" onclick="getdata(this.value,'1')">
<input type="button" value="N" onclick="getdata(this.value,'1')">
<input type="button" value="O" onclick="getdata(this.value,'1')">
<input type="button" value="P" onclick="getdata(this.value,'1')">
<input type="button" value="Q" onclick="getdata(this.value,'1')">
<input type="button" value="R" onclick="getdata(this.value,'1')">
<input type="button" value="S" onclick="getdata(this.value,'1')">
<input type="button" value="T" onclick="getdata(this.value,'1')">
<input type="button" value="U" onclick="getdata(this.value,'1')">
<input type="button" value="V" onclick="getdata(this.value,'1')">
<input type="button" value="W" onclick="getdata(this.value,'1')">
<input type="button" value="X" onclick="getdata(this.value,'1')">
<input type="button" value="Y" onclick="getdata(this.value,'1')">
<input type="button" value="Z" onclick="getdata(this.value,'1')">
<input type="button" value="Advance Search" id="addvance" class="AdvanceSearch">
</td></tr></table>
<form id="searchform" method="post" name="form">
<table>
<tr><td>Gender</td><td><input type="text" name="gender" id="gender"></td><td>Gautra</td><td><select name="gautra" id="gautra" >
<option value="">-Select Gautra-</option>
<option value="Sonigra">Sonigra</option>
<option value="Devda">Devda</option>
<option value="Jodha">Jodha</option>
<option value="Ranawat">Ranawat</option>
<option value="dulawat">Dulawat</option>
</select></td></tr>
<tr><td>First Name</td><td><input type="text" name="fname" id="fname"></td><td>Last Name</td><td><input type="text" name="lname" id="lname"></td></tr>
<tr><td>State</td><td><input type="text" name="state" id="state" ></td><td>City</td><td><input type="text" name="city" id="city"></td></tr>
<tr><td>Birth Place</td><td><input type="text" name="birth_place" id="birth_place"></td><td>Mobile Num.</td><td><input type="text" name="mobile" id="mobile"></td></tr>
<tr><td height="26"><input type="button" value="search" id="" class="AdvanceSearch button" onclick="search('1')" ></td></tr>
</table>
</form>
</div>
<div id="show1">
</div>
<div>
</div>
</div>
</body>
</html>