入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

Yii2中的Ajax,异步更新表单

创建时间:2015-06-09 投稿人: 浏览次数:2141
php页面的代码: <?php
$script= <<< JS
// here you write all your javascript stuff
$("#zipCode").change(function(){
    var zipId =$(this). val();
    $.get ("index.php?r=locations/get-city-province",{ zipId:zipId },function(result){
        var data =$. parseJSON(result );
        $ ("#customers-city"). attr("value",data .city);
        $ ("#customers-province"). attr("value",data .province);
    });
});
JS;
    $this ->registerJs( $script);

?> 控制器的代码: use yiihelpers Json; class LocationsController extends Controller
{
     public function actionGetCityProvince ($zipId){            //find the zipcode from the locations table
          
$location =Locations:: findOne($zipId );
          echo Json::encode ($location);
     } }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像