0

//on below code output occured is Undefined index: policy , how can i get the value of variable policy on controller

//product_view.php

    $(".product").on('change', function(){ 
    var policy= "gggggggggggg";
    var base_url = window.location.origin;
//alert(policy);
  $.ajax( {
  type: "POST",
  url: base_url+"/sales/index.php/Add_AMC/Insurance_chg",
  data: policy,
  success: function( response ) {
    alert(response);
  }
});
});

//Add_amc.php controller
//function Insurance_chg(){
        $product=$_POST['policy'];
        echo $product;die();
    }
Shubhangi
  • 69
  • 3
  • 1
    Use JSON structure to send data on server and retrieve post data by iterate JSON in php – dgk Dec 27 '16 at 06:46
  • Hi Shubhangi, please refer to given post for your solution http://stackoverflow.com/questions/6782230/ajax-passing-data-to-php-script – dgk Dec 27 '16 at 06:48
  • your ajax call look good,so problem maybe on radio button side,as it's showing undefined index error so make sure it's getting valid radio button id – Parth Goswami Dec 27 '16 at 06:59

2 Answers2

1

Problem may be at sending data....

     $(".product").on('change', function(){ 
    var policy= "gggggggggggg";
    //var base_url = 'window.location.origin';
//alert(policy);
  $.ajax( {
  type: "POST",
   url:<?php echo base_url('sales/index.php/Add_AMC/Insurance_chg');?>,
  data: {policy:policy},
  success: function( response ) {
    alert(response);
  }
});
});

OR you can send your data as..

data:'policy='+policy,

In codeigniter you can use the base_url() by loading the url helper.So not need to define base_url like this... So change

url: base_url+"/sales/index.php/Add_AMC/Insurance_chg",

to

url:<?php echo base_url('sales/index.php/Add_AMC/Insurance_chg');?>,
Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19
1

Try this code

$(".product").on('change', function(){ 
    var policy= "gggggggggggg";
    var base_url = window.location.origin;
    var var_data = "policy="+ policy;
  $.ajax( {
     type: "POST",
     url: base_url+"/sales/index.php/Add_AMC/Insurance_chg",
     data: var_data,
     success: function( response ) {
       alert(response);
     }
  });
});
dhruv jadia
  • 1,684
  • 2
  • 15
  • 28