php - JSON Parse error - iPad/iPhone Only -
i working within codeigniter framework , on page load making following ajax request:
$.ajax({ url: '/beta/images/loadimages', type: 'post', datatype: 'json', data: {id: id}, success: function(json, textstatus, xhr) { alert('success'); } }, error: function(json, textstatus, errorthrown) { alert(errorthrown); } });
strong text
public function loadimages() { $galleryid = $this->input->post('id'); $data = array('images' => $this->image_gallery->get_slideimages($galleryid) ); echo json_encode($data); }
finally model
public function get_slideimages($galleryid) { $this->db->select('id'); $this->db->where('galleryid', $id); $query = $this->db->get('image_images'); $result = $query->result(); return $result; }
json return in chrome
{"images":[{"id":"34","galleryid":"57","clientref":"205","imagename":"769074051374530545.jpg","orgname":"p9180021.jpg","order":"0","timestamp":"1374530546"}]}
the error occurs on ipad , iphone. syntaxerror: json parse error: unrecognized token '<' ideas on one?
url: '/beta/images/loadimages', type: 'post'
if loading (especially on page load), why use post
? use get
instead.
you getting json parse error because aren't returning valid json (you returning html/xml). possible explanation have server side logic dictates
if browser == mobile return html/xml else return json
Comments
Post a Comment