简体   繁体   中英

passing jquery variable to codeigniter view

i'm trying to pass jQuery variable to my codeigniter view through controller. i have some input fields in my form but i dont want the input fields values to be captured in my controller method.

<form action="controller_name/method_loading_view" method="get">
  //input fields
  <input type="submit" onclick='myFunction()' /> 
</form>

<script type="text/javascript">
    function myFunction(){
            var code=128;
            var qty=10;
            var base_url='http://localhost/sitename/';
                $url = base_url+'controller_name/method_loading_view';
                $.get($url, {pcode: this.code, pqty: this.qty});
              }   
</script>

and then i'm trying to get the values in my codeigniter method with $_GET

$code = $_GET['pcode'];
$qty = $_GET['pqty'];

You have defined 'var code=128; var qty=10;' in method so no need to pass it with this.code and this.qty

Try to set it like

$.get($url, {pcode: code, pqty: qty});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM