I am using codeigniter along with a jquery ajax call. I get a response from the server but when I try to alert the data contained from the response it just says “parseerror”, how do I get the entire data, see my code below:
I get this response, alongside an error in Firebug:
ERROR
[B]missing ; before statement
</div><div style=“border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;”[/B]
VIEW
$(document).ready(function(){
$.ajax({
url: "http://domain.com/179/index.php/api/user",
data: "format=jsonp&id=1",
dataType: "jsonp",
type: "GET",
success: function(data) {
var json = $.parseJSON(data);
alert(json)
},
error: function(err, msg){
var json = $.parseJSON(data);
alert(json)
}
});
})
CONTROLLER
class Api extends REST_Controller
{
function user_get($x)
{
$id = $this->get('id');
if(!isset($id))
{
$this->response(NULL, 400);
}
// validate user
$this->load->model('model_admin');
$user = $this->model_admin->get_data($id);
if($user)
{
$this->response($user, 200); // 200 being the HTTP response code
}
else
{
$this->response(NULL, 404);
}
}
The JSON contained inside http://domain.com/179/index.php/api/user
([{"id":"1","first_name":"John","last_name":"smith"}])
Also, for example, I would like to alert John smith (from above json)… how would I do that in the view??