当从选择框中选择值时,ajax调用控制器

时间:2017-12-04 07:04:31

标签: php ajax select controller

我想在值时对控制器进行ajax调用 从选择框中选择。

这是我的代码:

<select class="form-control required"  name="law_name" id="law_name">
    @foreach($law_name as $lawname)
    <option value="{{$lawname->id}}">{{$lawname->law_name}}
    </option>
 @endforeach    
 </select>

<script>
    $("#law_name").on('change', function(){
                alert('123');
                $.ajax({
                        type: 'POST',
                        dataType: "json",
                        data: data,
                        url: "{{ URL::to('admin/SubLawController/index') }}",
                        success: function (response) {
                        }
                    });
                });
</script>

当我从选择框中更改值

时,我的脚本未运行

1 个答案:

答案 0 :(得分:0)

以下是用于在下拉框的更改事件上进行ajax调用的jquery代码,

  final Button down_install = (Button) findViewById(R.id.bt_down_install);
        final Button start = (Button) findViewById(R.id.bt_start);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    boolean isAppInstalled = appInstalledOrNot("com.facebook.android");
                    if (isAppInstalled) {
                        Intent Start_screen = new Intent(SplashScreen.this, MainActivity.class);
                        startActivity(Start_screen);

                    } else {

                        start.setEnabled(false);


                }

            }

            private boolean appInstalledOrNot(String uri) {
                PackageManager pm = getPackageManager();
                try {
                    pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                    return true;
                } catch (PackageManager.NameNotFoundException e) {
                }

                return false;


            }
        });

代码在jquery中,你必须使用xmlhttprequest对象来实现痛苦的javascript。