ReactJS 渲染函数语法错误

ReactJS error in syntax at render function

我写了一个反应 class 但是 Chrome 在渲染函数中抛出语法错误。

我在这里附上代码:

var Chatrooms = React.createClass({

    getInitialState: function() {
        return {
            loaded: false,
            pages: undefined,
            id: "-1",
        };
    },

    loadPages: function() {
        url = "/chat/api/chatroom/" + this.props.course + "/get/?format=json";
        request = ajax_json_request(url, "GET", {});
        request.done(function(response) {
            response = jQuery.parseJSON(response);
            oldState = this.state;
            oldState['chatrooms']=response;
            oldState['loaded']=true;
            this.setState(oldState);
        }.bind(this));
    },

    componentDidMount: function() {
        if(!this.state.loaded) {
            this.loadPages();
        }
    },

    render: function(){
        console.log(this.state.chatrooms);
        return (
                <div></div>
            );
    }

});

浏览器将第 <div></div> 行中的错误显示为 Uncaught SyntaxError: Unexpected token <。我在线检查了语法,对我来说看起来不错。

您必须使用 <script type="text/javascript"> 而不是 <script type="text/jsx">

尝试在 JSX 文件顶部添加 JSX pragma:

/** @jsx React.DOM */

这是告诉浏览器使用 JSX 指令。