我在我的应用程序中有以下Axios放置请求。它正在调用Spring RestRepository资源。
axios.put(journal._links.self.href, journal)
.then(response => alert("Responded: " + JSON.stringify(response)))
.catch((error)=> {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
alert('Data: ' + error.response.data);
alert('Status: ' + error.response.status);
alert('Headers: ' + error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
alert('Request: ' + JSON.stringify(error.request));
alert('Error: ' + error.message);
} else {
// Something happened in setting up the request that triggered an Error
alert('Error: ' + error.message);
}
})
在Chrome中,我得到了预期的“已响应”响应。但是在Safari中,我得到
Request: {}
Error: Network Error
使用Firefox,除了控制台显示,根本没有生成任何警告框
NS_ERROR_XPC_SECURITY_MANAGER_VETO
有关如何追踪错误源的任何想法
显然,问题是我使用以下方法定义了提交按钮:>
<button onClick={this.doSave} > Save Changes </button>
这是默认类型
submit
,因此在Safari / Firefox尝试提交表单时出现了竞争情况。将type="button"
添加到button
标签可以解决该问题,并且一切都会按预期进行。