0

こんにちは友人私は私のドロップダウンリストに私のajax出力を追加しようとしています...。

私のajax関数:-

 $.ajax({ 
     url: "getcolumn",
     data: {value: value},
     type: "POST",
     success: function(output) {
        var column = output;//here i am assigning the output to another variable
        var mySelect = $('#table_name');
        $.each(column, function(val, text) {
          mySelect.append($('<option></option>').val(val).html(text));
        });

フォームのドロップダウン:-

echo $this->Form->input('Column', array(
    'label' => 'Select the column name below',
    'name' => 'tablename',
    'id' => 'table_name',
    'options' => array('null')
));

ajaxからの出力を上記のドロップダウンボックスに追加したい....ajax成功関数に追加しようとしましたが、機能しません。誰かが私を助けることができますか....そして出力はjsonの形式です.....

4

2 に答える 2

0

jqueryが機能するようにgetcolumnスクリプトに正しいjsonを作成すると、jsonは次のようになります。

[{id: 86,label: "venue and address"}, {id: 87,label: "venue and address"}]

次に、ループを少し変更します。

mySelect.append($('<option></option>').val(text.id).text(text.label));
于 2013-02-19T11:31:46.770 に答える
0

これを試して:

$.ajax({ 
 url: "getcolumn",
 data: {value: value},
 type: "POST",
 contentType: "application/json", //<----add this
 dataType: "json"                 //<----and this
 success: function(output) {
    var column = output;//here i am assigning the output to another variable
    var mySelect = $('#table_name');
    $.each(column, function(val, text) {
      mySelect.append($('<option></option>').val(val).html(text.id));
    });
 }
 });
于 2013-02-19T11:24:57.780 に答える