AJAX发送值但无法在PHP中检索

时间:2015-11-04 02:30:21

标签: php jquery ajax

您好我尝试传递链接中的值并使用$ _GET来接收值。我在我的本地尝试了这个,但是当我把它转移到现场时它不会收到参数值。

我尝试过使用firebug我可以看到值存储在链接中。但无法$ _GET他们。

AJAX

function getDivUpdate(val) {

    var group = $("#grp").val();
    var div   = $("#div").val();
        $.ajax({
            type: "GET",
            url: "<?=base_url()?>personnel/get_division_update/",
            data:{"group": group, "div": div},
            success: function(data){
                $('#div1').html(data);
             }
        }); 
}

PHP

function get_division_update($val=NULL){

            if(isset($_GET['group'])){  
            $select = "d_divname,dr_division";
            $table = "tbl_division";
            $where = "dr_group = $_GET[group]";
            $join1 = "tbl_division_rel";
            $join2 = "d_id = dr_division";

            echo "<select class='fieldnames' id='div' name='div'>";
            echo "<option value=''>--Select--</option>";
            $division = $this -> Main -> select_data($select, $table, $where, $join1, $join2);
            foreach($division as $div){


                echo '<option value="'.$div['dr_division'].'"'; 
                if($div['dr_division'] == $_GET['div'])
                    { echo "selected=selected"; } echo ">"; 
                echo htmlspecialchars($div['d_divname']).'</option>';       

            }

            }

            else if(isset($_GET['div']) OR isset($_GET['group'])){

            $table="tbl_division";
            $select="*";
            $orderby="d_divname";
            $divs = $this -> Main -> dropdown_orderby($select, $table, $orderby);

            echo "<select class='fieldnames' id='div' name='div'>";
            echo "<option value=''>--Select--</option>";
            foreach($divs as $d){
                echo "<option value='".$d['d_id']."'>".$d['d_divname']."</option>";
            }

            }

            else if(!isset($_GET['div']) AND !isset($_GET['group'])){


            $table="tbl_division";
            $select="*";
            $orderby="d_divname";
            $divs = $this -> Main -> dropdown_orderby($select, $table, $orderby);

            echo "<select class='fieldnames' id='div' name='div'>";
            echo "<option value=''>--Select3--</option>";
            foreach($divs as $d){

                echo "<option value='".$d['d_id']."'>".$d['d_divname']."</option>";
            }


            }
        }

2 个答案:

答案 0 :(得分:0)

请求是否真的成功,因为您需要回显基本网址以获取路径,因为base_url()返回值,而不是打印值,请尝试更改为以下代码:

url: "<?= echo base_url()?>personnel/get_division_update/", 
// or
url: "<?= echo base_url('personnel/get_division_update/')?>", 

答案 1 :(得分:0)

修正了问题。我刚刚更改了我的codeigniter的uri协议

$config['uri_protocol'] = 'QUERY_STRING';

$config['uri_protocol'] = 'AUTO';