【发布时间】:2013-09-19 01:58:13
【问题描述】:
查看文件:
<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 中。现在将输出作为数组值获取,我想拆分该数组值。我花了一整天的时间来完成这项任务,但我无法解决。
【问题讨论】:
-
我们使用 split 函数从一个重复字符的字符串中创建一个数组。你到底要什么?
-
您应该使用
console.log()而不是alert()。它更容易使用,并且输出将到达您已经显示在屏幕上的 JavaScript 控制台。
标签: javascript jquery ajax arrays codeigniter