Jquery getJSON Uncaught SyntaxError: Unexpected token : error

后端 未结 4 1386
面向向阳花
面向向阳花 2021-01-03 16:27

I am trying to connect to the RubyGems API, but when I try to get the JSON I get an stange error.

Uncaught SyntaxError: Unexpected token :

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 16:51

    Related... If you are not returning valid JSON you will see this error, JSONP aside.

    For me I was

    format.json { render :json => ActiveSupport::JSON.encode({:foo => true}) :status => :ok }
    =>
    {
      'foo': true
    }
    

    When I should have been

    format.json { render :json => ActiveSupport::JSON.encode([{:foo => true}]) :status => :ok }
    =>
    [
      {
        'foo': true
      }
    ]
    

提交回复
热议问题