I am using codeigniter rest ful api service for my website and using json response. We implemented it with ajax. The code is perfectly working in localhost but it is not working in online. It is showing a 200 response but json data is not parsing in ajax the below is the code
$(document).ready(function() {
$.ajax({
url: "<?php echo base_url();?>news/news.json",
type: "POST",
data: "",
success: function(data, textStatus, jqXHR) {
var news_title, news_id, new_image;
var json = $.parseJSON(JSON.stringify(data));
var str2;
$.each(json, function(idx, obj) {
news_title = obj.news_title_en;
news_id = obj.news_id;
new_image = obj.news_image_en;
str2 = "";
str2 += '<a href="<?php echo base_url();?>news_detail/' + news_id + '">';
if (new_image != '') {
str2 += '<img src="<?php echo base_url();?>admin/uploads/news/small/' + new_image + '" alt="' + news_title + '" /><span style="width:187px;font-size:13px;">' + news_title.substring(0, 22) + '</span>';
} else {
str2 += '<img src="<?php echo base_url();?>images/no-image.jpg" alt="' + news_title + '" /><span style="width:187px;font-size:13px;">' + news_title.substring(0, 22) + '</span>';
}
str2 += '</a>';
$('#news').append(str2);
});
},
error: function(jqXHR, textStatus, errorThrown) {
$('#news').append('No News to display');
}
});
$.ajax({
url: "<?php echo base_url();?>events/events.json",
type: "POST",
data: "",
success: function(data, textStatus, jqXHR) {
var events_id, events_title_en, events_image_en;
var json = $.parseJSON(JSON.stringify(data));
var str3;
$.each(json, function(idx, obj) {
events_title = obj.events_title_en;
events_id = obj.events_id;
events_image = obj.events_image_en;
str3 = "";
str3 = '<a href="<?php echo base_url();?>events_detail/' + events_id + '">';
if (obj.events_image_en != '') {
str3 += '<img src="<?php echo base_url();?>admin/uploads/events/small/' + events_image + '" alt="' + events_title + '" /><span style="width:187px;">' + events_title.substring(0, 22) + '</span>';
} else {
str3 += '<img src="<?php echo base_url();?>images/no-image.jpg" alt="' + events_title + '" /><span style="width:187px;">' + events_title.substring(0, 22) + '</span>';
}
str3 += '';
$('#events').append(str3);
});
},
error: function(jqXHR, textStatus, errorThrown) {
$('#events').append('No Events to display');
}
});
});
For the first section news it is working perfectly fine in online and in local both are working fine. Please let me know what is the issue
The below is my controller code
public function events_post($id="")
$data=array();
$post=$this->input->post();
$id=$post['id'];
$session_data = $this->session->all_userdata();
$this -> load -> model('events_model', 'Events');
$data=$this->Events->getEvents($id);
$this->response($data);
public function events_detail_get($id="")
$data=array();
$session_data = $this->session->all_userdata();
$data['page_name']='events';
$this->load->view($this->site_lang.'/layouts/header-'.$this->site_lang.'.php',$data);
$this->load->view($this->site_lang.'/events-detail-'.$this->site_lang.'.php',$data);
$this->load->view($this->site_lang.'/layouts/footer-'.$this->site_lang.'.php',$data);