PHP function does not display string after "&"

I use CI and windows 7. From my view file, I call a function in ajax, which is in the controller. In my ajax, I pass the line as Pack & Send, but when I repeat the same line in the controller function, it just echoes Pack.

My ajax call looks like

<script>
      $(document).ready(function(){
        $("select#items").change(function(){
            var country_id =  $("select#items option:selected").attr('value'); 
            $("#state").html( "" );
            $("#city").html( "" );
            if (country_id.length > 0 ) { 
             $.ajax({
                    type: "POST",
                    url: "<?php echo site_url('ga_api/sample/ajax_second_dropdown');?>",
                    data: "country_id="+country_id,
                    cache: false,
                    beforeSend: function () { 
                        $('#state').html('<img src="<?php echo IMAGE_PATH;?>loader.gif" alt="" width="24" height="24">');
                    },
                    success: function(html) {    
                        $("#state").html( html );
                    }
                });
            } 
          alert(country_id);
        });
      });
    </script>

In warning mode, I get a whole line, i.e. Pack & Send.

Now my php function in the controller

function ajax_second_dropdown()
{
    echo $_POST["country_id"]; 
}

It's just an echo here Pack

I thought it could be due to a special character. But I think this is not a scene, when I tried to change &to, %, ', \, \&, etc. In these cases, I get the whole string.

+4
source share
2 answers

& - : . , ?var1=x&var2=y.

URL- HTTP:

data: "country_id="+encodeURIComponent(country_id),
+6

, , : Escape , jquery ajax

"&" , ( , ). (encodeURIComponent), , , , - _.! ~ * '()

: encodeURIComponent

:

data:"country_id="+encodeURIComponent(country_id),
+1

All Articles