ファイルを閲覧する:
<form name="sortdata" method="POST" action="<?php echo base_url;?>home/sortby">
<select id="sortMyData" name="sortMyData" class="sortMydata">
<option value="lowhigh">Low to high price</option>
<option value="highlow">High to low price</option>
</select>
<input type="hidden" id="baseurl" name="baseurl" value="<?php echo base_url;?>">
</form>
<div id="sortbyprice" class="span6">
</div>
<script type="text/javascript">
$(document).ready(function()
{
$(".sortMydata").change(function()
{
var baseurl=$("#baseurl").val();
var sortMyData=$("#sortMyData").val();
//alert(baseurl);
alert(sortMyData);
$.ajax
({
type:"GET",
url:baseurl + 'product/sortbydetails/' + sortMyData,
//data:this.value,
cache: false,
success:function(html)
{
var length=html.length;
alert(html);
alert(html[0]);
}
});
});
});
</script>
コントローラ:
public function sortbydetails()
{
$lowhigh=$this->uri->segment(3);
if($lowhigh=="lowhigh")
{
$lowtohighprice=$this->product_model->getlowtohighprice();
$count=count($lowtohighprice);
//echo $count;
for ($i=0; $i < $count ; $i++)
{
foreach ($lowtohighprice as $key => $value) {
$sortby[] = array_values($value);
}
print_r($sortby);
}
//print_r($lowtohighprice);
}
else
{
$hightolowprice=$this->product_model->gethightolowprice();
//print_r($hightolowprice);
}
}
javascript から配列値を分割しようとしています。jquery ajax コードを作成し、出力を div に表示しました。出力を配列値として取得しています。その配列値を分割したいと思います。このタスクを達成するために丸一日を費やしましたが、解決できませんでした。