//在下面的代码输出上发生的是Undefined index:policy,如何在控制器上获取变量策略的值
// 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();
}
答案 0 :(得分:1)
问题可能在于发送数据....
$(".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);
}
});
});
或者您可以将数据发送为..
data:'policy='+policy,
在codeigniter中,你可以通过加载base_url()
助手来使用url
。所以不需要像这样定义base_url
......
所以改变
url: base_url+"/sales/index.php/Add_AMC/Insurance_chg",
到
url:<?php echo base_url('sales/index.php/Add_AMC/Insurance_chg');?>,
答案 1 :(得分:1)
试试此代码
$(".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);
}
});
});