dsa88886666 2017-10-29 10:22
浏览 29
已采纳

如何在URL中获取变量php到javascript

I have a code javascript

$(document).ready(function() {

            //datatables
            table_pertanyaan = $('#table_pertanyaan').DataTable({ 

                "processing": true, //Feature control the processing indicator.
                "serverSide": true, //Feature control DataTables' server-side processing mode.
                "order": [], //Initial no order.

                // Load data for the table's content from an Ajax source
                "ajax": {
                    "url": "<?php echo site_url('pertanyaan/ajax_list/')?>/" + id,
                    "type": "POST"
                },

                //Set column definition initialisation properties.
                "columnDefs": [
                { 
                    "targets": [ -1 ], //last column
                    "orderable": false, //set not orderable
                },
                ],

            });

And I have a parameter in URL localhost/ci/edit/87 87 is id.

How to I get variable from URL to use Javascript code?.

  • 写回答

2条回答 默认 最新

  • dqxz96998 2017-10-29 10:43
    关注

    There is a much better way to do this if you are using CodeIgniter.

    This is an answer specific to your question which requires a JavaScript answer.

    Assuming the url will always be having edit before id.

    var url_parts = window.location.pathname.split('/');
    var id =  url_parts[url_parts.indexOf("edit")+1];
    

    If you want the CodeIgniter solution, I suggest you search for it because its already answered or comment and I'll tell you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序