1

ドロップダウン メニューから複数の項目を選択できる autosuggest プラグインを使用しています (デモはこちら)。クエリを php ファイルに送信し (後でクエリ自体に夢中になります)、ページを離れることなく結果を取得したいと考えています。

現在、php ファイルはほとんど空です。

<?php print_r($_REQUEST); ?>

しかし、検索ボックスが正しく表示されなくなったため、どこかで jquery を間違えたことはわかっています。

これが私が作成したコードです。「データ」フィールドに何を入力すればよいかわかりません。

 <script type="text/javascript">
            $(document).ready(function(){                
                $("#select3").fcbkcomplete({
                    json_url: "data.txt",
                    addontab: true,                   
                    maxitems: 10,
                    input_min_size: 0,
                    height: 10,
                    cache: true,
                    newel: false,
                    filter_selected: true,
                    maxitimes: 5,


                    // I did this
                    onselect:"get_venue",




                });


    // I also did this

    function get_venue() {
    $("#select3 option:selected").each(function() {
$.ajax({
        type: 'POST',
        url: 'post.php',
        dataType: 'json',
        data: {
            WHAT DATA GOES HERE?
        },
success : function(data){
                $('#phpmessage').removeClass().addClass((data.error === true) ? 'error' : 'success')
                    .text(data.msg).show(500);
                if (data.error === true)

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $('#waiting').hide(500);
                $('#phpmessage').removeClass().addClass('error')
                    .text('There was an error.').show(500);
            }
        });       
    });
}





            });
        </script>

皆さん、こんなに長い投稿でごめんなさい:)!! ありがとう :))

私が得ているエラー:

関数ではありません: return func.call(func, _object);

function funCall(func, item) {
var _object = {};
for (i = 0; i < item.get(0).attributes.length; i++) {
if (item.get(0).attributes[i].nodeValue != null) {
_object["_" + item.get(0).attributes[i].nodeName] = item.get(0).attributes[i].nodeValue;
}
}
return func.call(func, _object);
}
function checkFocusOn() {
if (focuson == null || focuson.length == 0) {
return false;
}
return true;
} 
4

1 に答える 1

1

検索ボックス内の各項目をループしたい場合、これらのクラスは.bit-box. これらの検索用語の配列を作成し、それらをデータとして ajax リクエストに送信します。

function get_venue() {
var data = []; 
$('.bit-box').each(function() {
    data.push( $(this).text );     
}); 

$.ajax({
        type: 'POST',
        url: 'post.php',
        dataType: 'json',
        data: {
            'choices[]': data
        },
    success : function(data){
              $('#phpmessage')
               .removeClass()
               .addClass((data.error === true) ? 'error' : 'success')
               .text(data.msg).show(500);
            if (data.error === true){ 
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            $('#waiting').hide(500);
            $('#phpmessage').removeClass().addClass('error')
                .text('There was an error.').show(500);
        }
});       
}
于 2011-09-14T18:12:00.327 に答える