function checkAvailability() {
$("#loaderIcon").show();
jQuery.ajax({
url: "check_availability.php",
data:'flatno='+$("#flatno").val(),
type: "POST",
success:function(data){
$("#flatno-availability-status").html(data);
$("#loaderIcon").hide();
},
error:function (){}
});
}
<div>
<input name="block_id" type="hidden" id="block_id" value="somevalue">
</div>
<div id="frmCheckflatno">
<label>Flat Number:</label>
<input name="flatno" type="text" id="flatno" onBlur="checkAvailability()"><span id="flatno-availability-status"></span>
</div>
<p><img src="LoaderIcon.gif" id="loaderIcon" style="display:none" /></p>
脚本将值flatno
发送到check_availability.php
并从数据库查询信息。现在我需要向flatno
发送两个值blockno
和check_availability.php
,以便我可以使用2个约束来检查数据库。
答案 0 :(得分:0)
将数组发送到您的后端:
<script>
function checkAvailability() {
$("#loaderIcon").show();
var fn = $("#flatno").val();
var bn = $("#blockno").val();
jQuery.ajax({
url: "check_availability.php",
data: {flatno: fn, blocno: bn},
type: "POST",
success: function (data) {
$("#flatno-availability-status").html(data);
$("#loaderIcon").hide();
},
error: function () {}
});
}
</script>
当然最好在调用php脚本之前检查两个字段中是否有任何值。
答案 1 :(得分:0)
function checkAvailability() {
var flatnoValue = $("#flatno").val();
var blocknoValue = $("#block_id").val();
$("#loaderIcon").show();
jQuery.ajax({
url: "check_availability.php",
data:'{flatno:flatnoValue,blockno:blocknoValue},
type: "POST",
success:function(data){
$("#flatno-availability-status").html(data);
$("#loaderIcon").hide();
},
error:function (){}
});
}
<div>
<input name="block_id" type="hidden" id="block_id" value="somevalue">
</div>
<div id="frmCheckflatno">
<label>Flat Number:</label>
<input name="flatno" type="text" id="flatno" onBlur="checkAvailability()"><span id="flatno-availability-status"></span>
</div>
<p><img src="LoaderIcon.gif" id="loaderIcon" style="display:none" /></p>