SuperNinja
SuperNinja

Reputation: 1606

JSON Parse error - iPad/iPhone Only

I am working within the codeigniter framework and on page load making the 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 the 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 only on the iPad and iPhone. SyntaxError: JSON Parse Error: Unrecognized token '<' Any ideas on this one?

Upvotes: 0

Views: 984

Answers (1)

Brad M
Brad M

Reputation: 7898

url: '/beta/images/loadImages',
type: 'POST'

If you are just loading something (especially on page load), why use POST? Use GET instead.

You are getting the JSON parse error because you aren't returning valid JSON (you are returning html/xml). The only possible explanation is you have some server side logic that dictates

if browser == mobile 
     return html/xml 
          else 
     return JSON

Upvotes: 1

Related Questions