这是我的javascript代码:
<script type="text/javascript">
$(document).ready(function(){
$("#sepatu").click(function(e){
e.preventDefault();
var site_url = "<?php echo base_url()?>index.php/pelanggan/dyos_sepatu/";
$("#content").load(site_url);
})
})
</script>
这就是我要加载的内容:
<select name="jenis" class="form-control">
<?php
foreach ($jenis->result() as $data){?>
<option value="<?php echo $data->id_jenis_sepatu?>"><?php echo $data->nama_jenis?></option>
<?php
}
?>
</select>
我在添加php脚本后出现问题:
<?php
foreach ($jenis->result() as $data){?>
<option value="<?php echo $data->id_jenis_sepatu?>"><?php echo $data->nama_jenis?></option>
<?php
}
?>
它不会加载。当我删除该脚本时,它会加载。 这是我的控制器:
public function dyos_sepatu(){
$data['jenis'] = $this->db->query("SELECT * FROM jenis_sepatu");
$this->load->view('pelanggan/sepatu_dyos',true,$data);
}
答案 0 :(得分:0)
将数据发送到以下视图
public function dyos_sepatu(){
$data['jenis'] = $this->db->query("SELECT * FROM jenis_sepatu")->result();
$this->load->view('pelanggan/sepatu_dyos',true,$data);
}
然后在$jenis->result()
视图中$jenis
。尝试一次
喜欢这个......
<?php
foreach ($jenis as $data){?>
<option value="<?php echo $data->id_jenis_sepatu;?>"><?php echo $data->nama_jenis;?></option>
<?php
}
?>
答案 1 :(得分:0)
试试这个;
public function dyos_sepatu(){
$data['jenis'] = $this->db->query("SELECT * FROM jenis_sepatu");
echo $this->load->view('pelanggan/sepatu_dyos',true,$data); // note the echo here
}
需要将内容回显到页面jQuery .load()
呈现页面。
答案 2 :(得分:-1)
我想你忘了在这个<?php echo $data->id_jenis_sepatu; ?>
中终止php。还要检查选项标签