douzao1119 2013-07-23 19:52
浏览 52

JSON解析错误 - 仅限iPad / iPhone

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?

  • 写回答

1条回答 默认 最新

  • dszpyf4859 2013-07-23 19:56
    关注
    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀