I am trying to dynamically load data based on the specific URI segment present on the page.
Below is my JavaScript code:
$(document).ready(function() {
$(function() {
load_custom_topics();
});
$('#topics_form').submit(function() {
var topic = document.getElementById('topics_filter').value
$.ajax({
type: "POST",
url: 'ajax/update_session_topic',
dataType: 'json',
data: { topic: topic },
success: function(){
load_custom_topics()
}
});
return false;
});
function load_custom_threads(){
$.ajax({
type: "POST",
url: 'ajax/load_custom_threads',
dataType: 'json',
data: {},
success: function (html) {
$('div.topics_filter').html(html['content']);
get_discussions();
}
});
}
function get_discussions(){
var page = document.getElementById('page').value
$.ajax({
type: "POST",
url: 'ajax/get_discussions',
dataType: 'json',
data: {page: page},
success: function (html) {
$('div#discussion_list').html(html['content']);
}
});
}
});
Initially, load_custom_topics()
function executes perfectly. It should then trigger get_discussions()
. However, it seems to halt at this point and no data is retrieved.
Here's the implementation of get_discussions()
:
public function get_discussions()
{
$session = $this->session->userdata('active_topic');
if ($this->input->post('page') == '1')
{
$data['list'] = $this->right_model->thread_list_all();
$data['test'] = "all";
} else {
$data['list'] = $this->right_model->thread_list_other($session);
$data['test'] = "not all";
}
if ($data['list'] == FALSE)
{
$content = "no hits";
} else {
$content = $this->load->view('right/thread_list', $data, TRUE);
}
$data['content'] = $content;
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
Although I dynamically generate the 'page' attribute, the HTML output appears like this:
<div name="page" value="1"></div>
Can anyone identify why the get_discussions()
function is not being executed?