Milon Hossain
Milon Hossain

Reputation: 41

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'];

Upvotes: 0

Views: 53

Answers (1)

Chirag Chhuchha
Chirag Chhuchha

Reputation: 395

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});

Upvotes: 2

Related Questions