【问题标题】:How can access base Site URL id into ajax and pass to controller using Codeigniter?如何将基本站点 URL id 访问到 ajax 并使用 Codeigniter 传递给控制器​​?
【发布时间】:2019-05-14 10:16:02
【问题描述】:

我是 Codeigniter 的新手

我想在 AJAX 中访问基本 URL ID,我还将另一个 ID 传递给 Codeigniter 中的控制器。在控制器端,我访问两个不同的 id 一个 site_url id 和另一个 s_id。

那么我该如何完成这个任务呢?

Site URL

https://www.demoexample.com=?uid=10

Ajax脚本

<script>
 $(document).ready(function(){

    $('#member_type').on('change',function(){

        var memId = $(this).val();

        if(memId!=''){
                       $.ajax({

                               url: "<?php echo site_url('index.php/template/vehicle/get_member_type')?>",

                               method:'POST',
                               data:'member_id='+memId, // here I want to access site_url id and s_id from drop-down id

                               success:function(data)
                               {
                                  $('#mid').html(data);

                               }
                             }); 
        }
        else{
           $('#mid').html('<option value="">Select sttxt_Standard first</option>'); 
        }
    });
});
</script>

控制器.php文件

   function show_vehicle_reg(){   

            $id=$this->input->post('id'); // access multiple id over here from ajax

        }
    }

提前致谢

【问题讨论】:

  • 向我们展示您的代码,以便我们查看您的错误部分

标签: php ajax codeigniter


【解决方案1】:

ajax:
GET 方法

$.ajax({
    beforeSend: function () {
    },
    complete: function () {
    },
    type: "GET",
    url: "<?php echo site_url('controller/cmethod/'.$s_id); ?>",
    success: function (data) {

    }
});

POST方法

$.ajax({
    beforeSend: function () {
    },
    complete: function () {
    },
    type: "POST",
    url: "<?php echo site_url('controller/cmethod'); ?>",
    data: ({member_id: memId}),
    success: function (data) {

    }
});

【讨论】:

    猜你喜欢
    • 2016-09-09
    • 2011-11-03
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多