我在從codeigniter複選框中檢索數據時遇到問題。 我的看法是Ajax返回數據錯誤
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
var base_url = '<?=base_url()?>';
function test()
{
var country = document.forms["fetch_country"].country;
var countryText = ''
for (i=0;i<country.length;i++)
{
if (country[i].checked)
{
countryText = countryText + country[i].value + ","
}
}
// alert(countryText)
var type= countryText;
// alert (type);
$.ajax({
url: base_url+'/index.php/ajax_test/index',
type : 'POST', //the way you want to send data to your URL
data : {'type' : type},
success : function(result){ //probably this request will return anything, it'll be put in var "data"
alert (type);
$('#div1').html(result); //jquery selector (get element by id)
}
});
// alert ("countryFinalValue is " + id);
}
</script>
</head>
<body>
<form id="fetch_country">
<div id="new">
<input id="country" type="checkbox" onclick="test()" value="1">India<br/>
<input id="country" type="checkbox" onclick="test()" value="2">USA<br/>
<input id="country" type="checkbox" onclick="test()" value="3">UK<br/>
<input id="country" type="checkbox" onclick="test()" value="4">China<br/>
</div>
</form>
<div id="div1"></div>
</body>
,我的控制器是:
<?php
class ajax_test extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->view('view_test');
}
public function index()
{
//$this->load->view('view_test');
$id = $this->input->post('type');
echo $id;
//$this->load->view('view_test' , $id);
}
}
?>
我面對的是我得到選中的複選框的值的問題,但與價值我得到一整套複選框反覆我的看法 。
你爲什麼使用'jquery 1.3.2'?其過時的伴侶 – Satpal
我可以獲得替代解決方案嗎? –