0

こんにちは、if 条件がまったく機能しない ajax コーディングがあります。プログラムが if ステートメントを満たしている場合でも、プログラムが else ステートメントを実行するたびにのみ機能します。

<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";
        }
    }
?>
4

3 に答える 3