“SyntaxError:意外的令牌<在位置0的JSON中”在處理類似Facebook的內容源的React應用程序組件中,我遇到了一個錯誤:Feed.js:94 undefined“parsererror”“SyntaxError:位于0的JSON中的意外標記<我遇到了一個類似的錯誤,結果是渲染函數中的HTML中的拼寫錯誤,但這似乎不是這里的情況。更令人困惑的是,我將代碼轉回到早期的已知工作版本,我仍然遇到錯誤。Feed.js:import React from 'react';var ThreadForm = React.createClass({
getInitialState: function () {
return {author: '',
text: '',
included: '',
victim: ''
}
},
handleAuthorChange: function (e) {
this.setState({author: e.target.value})
},
handleTextChange: function (e) {
this.setState({text: e.target.value})
},
handleIncludedChange: function (e) {
this.setState({included: e.target.value})
},
handleVictimChange: function (e) {
this.setState({victim: e.target.value})
},
handleSubmit: function (e) {
e.preventDefault()
var author = this.state.author.trim()
var text = this.state.text.trim()
var included = this.state.included.trim()
var victim = this.state.victim.trim()
if (!text || !author || !included || !victim) {
return
}
this.props.onThreadSubmit({author: author,
text: text,
included: included,
victim: victim })
this.setState({author: '',
text: '',
included: '',
victim: ''
})
},用console.error(this.props.url, status, err.toString()下劃線劃線。由于看起來錯誤似乎與從服務器中提取JSON數據有關,我嘗試從空白數據庫開始,但錯誤仍然存在。錯誤似乎是在無限循環中調用,大概是因為React不斷嘗試連接到服務器并最終導致瀏覽器崩潰。編輯:我已經使用Chrome開發工具和Chrome REST客戶端檢查了服務器響應,數據似乎是正確的JSON。編輯2:看來雖然預期的API端點確實返回了正確的JSON數據和格式,但React正在輪詢http://localhost:3000/?_=1463499798727而不是預期的http://localhost:3001/api/threads。我在端口3000上運行webpack熱重裝服務器,在端口3001上運行Express應用程序以返回后端數據。令人沮喪的是,這是我上一次工作時正常工作,無法找到我可以改變的東西來打破它。
“SyntaxError:意外的令牌<在位置0的JSON中”
子衿沉夜
2019-07-27 10:09:38