0

AJAXとPHPについて質問があります。メインのドロップダウンリストがあり、ユーザーがそれを変更すると、メインのドロップダウン値に基づいて他のドロップダウンが変更されることになっています。私が取り組んでいるウェブサイトには、ピックアップポート(メインドロップダウン)があります。ユーザーがこのピックアップポートを変更すると、AJAXとPHPを使用して変更されるはずのドロップダウンが他に4つあります。それを作成する方法を考えて、私は今3日間ほどそれに取り組んできましたが、成功しませんでした。

前もって感謝します。

私はこれを試しました

function filter(id) {
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('type_filter').innerHTML = xmlhttp.responseText;
            document.getElementById('find-trip-dest-region').innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open('GET', 'forms/type_filter.php?id=' + id, true);
    xmlhttp.send();
    xmlhttp.open('GET', 'forms/activity_filter.php?id=' + id, true);
    xmlhttp.send();
}

そしてこれも

function filter(id) {
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('type_filter').innerHTML = type_filter.responseText;
            document.getElementById('find-trip-dest-region').innerHTML = activity_filter.responseText;
        }
    }
    var type_filter = xmlhttp.open('GET', 'forms/type_filter.php?id=' + id, true);
    xmlhttp.send();
    var activity_filter = xmlhttp.open('GET', 'forms/activity_filter.php?id=' + id, true);
    xmlhttp.send();
}

そしてまたこれを試しました

function filter(id) {
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('type_filter').innerHTML = type_filter.xmlhttp.responseText;
            document.getElementById('find-trip-dest-region').innerHTML = activit_filter.xmlhttp.responseText;
        }
    }
    var type_filter = xmlhttp.open('GET', 'forms/type_filter.php?id=' + id, true);
    xmlhttp.send();
    var activit_filter = xmlhttp.open('GET', 'forms/activity_filter.php?id=' + id, true);
    xmlhttp.send();
}
4

1 に答える 1

0

私はこのようなjqueryを使用してそれを解決することができました

$(document).ready(function() {
    $('#pickup_port').change(function() {
        var id = $('#pickup_port').val();
        if(id != "") {
            $.get('forms/type_filter.php?id='+ id, function(data) {
                $('#type_filter').html(data);
            });
            $.get('forms/activity_filter.php?id='+ id, function(data) {
                $('#activity_filter').html(data);
            });

        }
    });
});

しかし、誰かがより良い解決策を持っていますか、それともこれが唯一の解決策です

于 2012-05-25T22:00:36.340 に答える