简体   繁体   中英

Yii2 Working with AJAX for get values

i have _form.php field

    <?php $form = ActiveForm::begin(); ?>

   <?= $form->field($model, 'IdKaryawan')->widget(Select2::classname(), [
        'data' => $listData,
        'options' => ['placeholder' => 'Pilih Karyawan...','id'=>'Nomor'],
        'pluginOptions' => [
            'allowClear' => true
        ],
    ]); ?>

    <?=  $form->field($model, 'IdJabDepAwal')->textInput(['maxlength' => 100])?>
    <?= $form->field($model, 'IdJabDep')->textInput(['maxlength' => 100])?>
    <?= $form->field($model, 'Alasan')->textarea(['rows' => 6]) ?>
    <?= $form->field($model, 'Status')->textarea(['rows' => 6])?>

it work just fine until i put this to fill the value below

 $script = <<< JS
    $('#Nomor').change(function(){
        var test = $(this).val();
        $.get('karyawan/get-IdJabDept',{ test : test },function(data){
            var data = $.parseJSON(data);
            $('#mutasi-IdJabDepAwal').attr('value',data.IdJabDept);

        });
    });

    JS;
    $this->registerJs($script);

the field IdJabDept wont updated.
how do i fix my code ? any helps is appriciated,

Change

$('#mutasi-IdJabDepAwal').attr('value',data.IdJabDept);

to

$("#mutasi-IdJabDepAwal").val(data.IdJabDept);

Try changing this:

$.get('karyawan/get-IdJabDept',{ test : test },function(data){

for this:

$.get('index.php?r=karyawan/get-IdJabDept',{ test : test },function(data){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM