drtoclr046994545 2017-02-17 06:39
浏览 70

如何将ajax从一个表单传递到另一个表单?

Yii2. I have two forms:

First - site.com/test1/form1

when I choose Test1, Ajax loads the data from the database in Test2 and Test3

But I need to load the data into a second form. I select Test1 in Form1, then I'm creating this form. After that I go to create Form2, and when form opens I see the downloaded data.

That's how it should be

StreetsController.php for data:

 public function actionGetNM($id)
{

    $street = Streets::findOne($id);
    echo Json::encode($street);
}

In _form1:

 $script = <<< JS
$('#form1-test1').change(function(){
    var id = $(this).val();

    $.get('/streets/get-n-m',{ id : id },function(data){
        var data = $.parseJSON(data);
        $('#form1-test2').attr('value',data.n);
        $('#form2-test3').attr('value',data.m);
    });
});

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

I think that after creation Form1 need to get id form1and transmit on form2, where Ajax gets data from Json. It's all in theory, I don't understand how to implement it. Can anyone help?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线