S
S
Sergey Beloventsev2017-06-02 16:48:18
Yii
Sergey Beloventsev, 2017-06-02 16:48:18

How to set up ajax correctly?

here is the part of the action responsible for the ajax request

$module=$this->module;
if (Yii::$app->request->isAjax) {
  $post=Yii::$app->request->post();
    if(!empty($post)){
      return $this->render('create', [
        'found'  =>null,
      ]);
    }else{
      $get=Yii::$app->request->get();
       foreach ($module->models as $value){
            if($value['class']===$get['className']){
                $found =$value;
                break;
            }
       }
       return $this->render('create', [
           'found'  =>$found,
       ]);
    }
}

here is the view here is the js script
<?php var_dump($found); ?>
$(".sortable-ui").on('click','.wells .showDropFile',function(e){
        e.preventDefault();
        var url = $(this).data('url');
        var id = $(this).parents('li.wells').attr('data-id');
        var className = $(this).parents('li.wells').attr('data-model');
        $.ajax({
            type: "GET",
            url:url,
            data:"id="+id+"&className="+className,
            success: function(data){
                alert(url);
            }
        });
    });

Why not the result of the
foreach loop ($module->models as $value){
if($value['class']===$get['className']){
$found =$value;
break;
}
}
or am I misunderstanding something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-06-02
@Sergalas

Why not the result of the loop

because you are displaying url and not data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question