0
從我的瀏覽一個我使用的是功能,使AJAX call.The功能不working.In控制檯中顯示的錯誤信息如下:笨Ajax調用不工作
POST http://localhost/jsnci/section/ajax_call_pop_district_data/10 404 (Not Found)
XHR finished loading:POST"http://localhost/jsnci/section/ajax_call_pop_district_data/10".
和我」米制作Ajax調用如下:
<script type="text/javascript">
function popDistrictData(){
var dist_id = document.getElementById("ddlDist").value;
jQuery.ajax({
type: "POST",
url: "<?=site_url()?>section/ajax_call_pop_district_data/"+dist_id,
dataType: 'json',
success: function(res) {
if (res)
{
jQuery("div#districtData").html(res.username);
}
}
});
}
</script>
什麼,我不明白的是在控制檯中,爲什麼在一開始顯示404錯誤,那麼 相同功能的執行?請幫助。
My controller code:
public function ajax_call_pop_district_data($did)
{
$dist_data = $this->District_model->pop_district_data($did);
echo $dist_data;
}
我的模型代碼:
public function pop_district_data($did)
{
$html_dist_data='';
$sql="SELECT d_name, d_about, d_attraction, d_howtoreach,d_img_nm
FROM districts
WHERE d_id= ?";
$query = $this->db->query($sql, array($did)); //<---Here passing parameter to sql query
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row)
{
$html_dist_data.='<strong>ABOUT '.$row['d_name'].'</strong>';
$html_dist_data.='<p>';
$html_dist_data.='<a href="#" class="alignright"><img src="'.site_url().'assets/admin/uploads/district_img/'.$row['d_img_nm'].'" alt="Map of '.$row['d_name'].'" class="alignright" /></a>';
$html_dist_data.= $row['d_about'];
$html_dist_data.='</p>';
if($row['d_attraction'] != ''){
$html_dist_data.='<strong>ATTRACTIONS</strong>';
$html_dist_data.= $row['d_attraction'];
}
if($row['d_howtoreach'] != ''){
$html_dist_data.='<strong>HOW TO REACH ?</strong>';
$html_dist_data.= $row['d_howtoreach'];
}
}
}
return $html_dist_data;
}
404是一個HTTP錯誤。這意味着你找不到資源(或服務器這麼說) – mehulmpt
ajax方法的控制器代碼是什麼? –
但是在控制器 –