Get data from controller by AJAX - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Get data from controller by AJAX (/showthread.php?tid=62641) |
Get data from controller by AJAX - vertisan - 08-09-2015 Hi! I tried get data from controller by AJAX but I wrote something wrong. Here is my code: CONTROLLER: PHP Code: $data['AcceptedServices'] = $this->AdminServices_model->GetAcceptedServicesAdmin(); // I get by result() VIEW: PHP Code: $(document).ready(function() { I want display this data first in console, but in console i recive 'error'. Where is the problem? RE: Get data from controller by AJAX - phpilyo - 08-09-2015 remove $this->load->view( 'admin/ServicesList', $data ); RE: Get data from controller by AJAX - CroNiX - 08-09-2015 You are returning 2 things, first the json and then an html view file. Jquery doesn't know what to do with that because it expects 'json' Try something like: PHP Code: //If the request was made via ajax, return the json and exit. Else return the view. So when going to the page, the view will be retrieved via normal get request, and the ajax request would return the json at the same time. Another approach would be to return both the view and the json as part of the json. PHP Code: $data['AcceptedServices'] = $this->AdminServices_model->GetAcceptedServicesAdmin(); // I get by result() Then in your ajax request, you will have the 'AcceptedServices' and 'html' that you can do with what you want. Code: $('#DawajDane').click(function() { RE: Get data from controller by AJAX - Blair2004 - 08-10-2015 Hi, maybe the returned response is not in json format. Check XHR request from Google Dev Tools. |