2015-09-05 47 views
0

我使用React.js從我的快遞服務器上獲取的評論列表中的URL的GET請求隨機變量,但我的GET網址不斷得到與像隨機變量字符串追加「?_1441474975073」React.js

// Error in Chrome console 

GET http://localhost:4000/comments.json?_=1441474975073 404 (Not Found) 
/comments.json error Not Found 

有人能告訴我爲什麼?

// main.js 
React.render(
    <CommentBox url="/comments" />, 
    document.getElementById('reactComment') 
); 

var CommentBox = React.createClass({ 
    componentDidMount: function() { 
     $.ajax({ 
      url: this.props.url, 
      dataType: 'json', 
      type: 'GET', 
      cache: false, 
      success: function(data) { 
       this.setState({comments: data}) 
      }.bind(this), 
      error: function(xhr, status, err) { 
       console.error(this.props.url, status, err.toString()); 
      }.bind(this) 
     }); 
    }, 
    ... 
}); 

// server.js 
app.get('/comments', function(req, res) { 
    Comments.find().exec(function(err, data) { 
     if (err) throw err; 
     res.json(JSON.parse(data); 
    }); 
}); 

回答

0

我不能留下評論,所以我只是在這裏回答。

您已設置cache: false以便jQuery追加時間戳,以便始終調用JSON的新副本。

但這不可能是404錯誤的原因。

+0

嘿謝謝你!你是對的。 –