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 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型