嗨,我有一些 ajax 编码,其中 if 条件根本不起作用,每当程序执行 else 语句时,即使程序满足 if 语句也只能工作。
<script type="text/javascript">
function CheckDetails()
{
var http = false;
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
var rid = document.new_booking.ph_number.value;
http.onreadystatechange = function() {
if (http.readyState == 4) {
var str_d = http.responseText;
if (str_d == "no") {
document.getElementById('cus_name').focus();
} else {
var str_details = http.responseText;
var arr_details = str_details.split("~");
document.new_booking.cus_name.value = arr_details[0];
document.new_booking.pick_aline1.value = arr_details[1];
document.new_booking.pick_aline2.value = arr_details[2];
document.new_booking.pick_area.value = arr_details[3];
document.new_booking.pick_pincode.value = arr_details[4];
document.new_booking.drop_aline1.focus();
}
}
}
http.open("GET", "ajax.php?evnt=det&rid=" + rid);
http.send();
}
</script>
其 ajax.php 文件如下所示
<?php
if ($_GET['evnt'] == 'det') {
$rid = $_GET['rid'];
include("configure.php");
$select = mysql_query("select * from new_booking where ph_number = '$rid'");
$count = mysql_num_rows($select);
if ($count > 0) {
$row = mysql_fetch_array($select);
echo $row['cus_name']
. "~" . $row['pick_aline1']
. "~" . $row['pick_aline2']
. "~" . $row['pick_area']
. "~" . $row['pick_pincode']
. "~" . $row['drop_aline1']
. "~" . $row['drop_aline2']
. "~" . $row['drop_area']
. "~" . $row['drop_pincode'];
} else {
echo "no";
}
}
?>