Get data from controller by AJAX |
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?
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() {
Hi,
maybe the returned response is not in json format. Check XHR request from Google Dev Tools.
NexoPOS 2.6.2 available on CodeCanyon.
|
Welcome Guest, Not a member yet? Register Sign In |