【发布时间】:2021-10-27 02:56:09
【问题描述】:
我在从 ReactJS 获取数据并将数据传递到 ASP.NET Web 服务时遇到问题。
仅在从数据库中获取数据时,其他获取功能正在工作。
为什么我会收到这些错误?我在这里做错了什么?
我相信它在我的signUp fetch 函数中。
我认为该响应是 fetch 无法读取来自服务器的响应 -
main.chunk.js:2417 POST http://localhost:50496/WebService.asmx/SignUp 500 (Internal Server Error)
SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (<anonymous>)
ReactJS
userData = {
fName: 'some',
lName: 'two one',
email: 'someonw@gmail.com',
password: 'se123456' }
我在 ReactJs 中的 fetch 函数 -
const signUp = (signUpData) => {
let data = {
firstName: signUpData.fName,
lastName: signUpData.lName,
emailAddress: signUpData.email,
password: signUpData.password,
};
fetch('http://localhost:50496/WebService.asmx/SignUp', {
body: JSON.stringify(data),
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
})
.then((response) => response.text())
.then(
(xml) =>
new window.DOMParser().parseFromString(xml, 'text/xml')
.documentElement.firstChild.textContent
)
.then((jsonStr) => JSON.parse(jsonStr))
.then((userData) => {
if (userData.d && userData.d.length > 0) {
setUser(userData);
} else {
console.log('error no data');
}
})
.catch((err) => {
console.log(err);
});
};
Chrome 出错 -
System.InvalidOperationException:缺少参数:firstName。 System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection 集合) System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest 请求) System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
SignUpWebMethod 正在 WebService 中工作。
[WebMethod]
public string SignUp(string firstName, string lastName, string emailAddress, string password)
{
return BLL.SignUp(firstName, lastName, emailAddress, password);
}
【问题讨论】:
标签: asp.net reactjs web-services fetch internal-server-error