[eluser]Andre Dublin[/eluser]
I'm having trouble returning data from my controller using an ajax post function. What happens here is the user will input a style number, submit that number to the controller. The controller grabs the value submitted, queries the database and returns the results to the controller then the controller returns an array that I then encode into json. But I keep getting a 500 Internal Server Error???
Here is my Controller
Code:
//return schools based on style id
public function search() {
$input = json_decode($this->input->post('obj'));
$style_id = $input['style_id'];
$parent_id = $input['parent_id'];
$data = array();
if ($q = $this->page_model->search_results($style_id, $parent_id)) {
$data = $q;
}
echo json_encode($data);
}
Here is my Model
Code:
//get all entries
function search_results($style_id, $parent_id) {
$options = array(
'Style' => $style_id,
'Parent_ID' => $parent_id
);
$this->db->select('*');
$this->db->from('pages');
$this->db->join('entry', 'pages.Page_ID = entry.Parent_Page_ID', 'inner');
$this->db->where($options);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
}
}
Here is my javascript
Code:
//dress style search
$($searchBtn).click(function(event) {
var style_id,
parent_id,
obj = {};
//get the value of the input fields
searchVal = event.currentTarget.previousSibling.value;
parentID = event.currentTarget.parentElement.childNodes[3].value;
//The object to be passed to the controller
obj = { 'style_id' : searchVal, 'parent_id' : parentID };
//POST the values in json notation, return the search results in json notation
$.post(base_url + 'index.php/page/search',
obj,
function(data) {
console.log(data);
},
'json');
return false;
});
I am autoloading my models.
Thanks in advance!