Uncaught SyntaxError: Unexpected token : valid JSON

This question already has an answer here:

  • Unexpected token colon JSON after jQuery.ajax#get 2 answers
  • json Uncaught SyntaxError: Unexpected token : 4 answers

  • To solve the error

    No 'Access-Control-Allow-Origin' header is present on the requested resource.

    you should add some codes in your server . Java version:

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    
        // ...
        response.addHeader("Access-Control-Allow-Origin", "*");
        // you can change * for your spec url. 
        // if * is used, any url can be access to the data.
    
        // ...
    }
    

    and you can use dataType: 'json'

    链接地址: http://www.djcxy.com/p/46016.html

    上一篇: 未捕获SyntaxError:在Codeignitor中使用jQuery Ajax时出现意外的令牌

    下一篇: 未捕获的SyntaxError:意外的标记:有效的JSON