javascript - ajax POST 问题 - 500 内部服务器错误
问题描述
我在运行项目时遇到问题。当我运行该项目时,我得到 500 个内部服务器。
我的代码:
客户端.cs
public class Client
{
public Client(string firstName, string id, string lastName)
{
FirstName = firstName;
LastName = lastName;
Id = id;
}
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("first_name")]
public string FirstName { get; set; }
[JsonProperty("last_name")]
public string LastName { get; set; }
}
在 Regression.aspx 文件中,当函数 Regression 工作时 - 然后我总是得到 500 错误
<script type="text/javascript" language="javascript">
function Regrestion() {
//get data by document.getElementById...
var d = {
first_name: firstName,
id: id,
last_name: lastName
}
$.ajax({
url: 'Registretion.aspx/AddNewClient',
method: "POST",
contentType: "application/json; charset=utf - 8",
dataType: 'json',
data: JSON.stringify(d),
success: function (flights) {
alert("succ");
}, error: function (error) {
alert("error");
}
});
}
</script>
Registry.aspx.cs 背后的代码
public partial class Registretion : System.Web.UI.Page
{
[System.Web.Services.WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod]
public static Client AddNewClient(Client c)
{
//more code
return c;
}
解决方案
500 internal server error表示服务器响应错误。后端(您的服务器端)存在一些问题。
它与 JavaScript 或 AJAX 无关。这也不是连接问题。
查看您的代码:您的Registretion.aspx.cs文件末尾是否缺少}括号?
推荐阅读
- java - java.time.Period normalize() 更改月份字段的符号和值,尽管其绝对值小于 12
- haskell - Haskell 和 Data.Array.//:为什么这个类型是正确的?
- discord.js - Discord.js 消息未定义。消息嵌入
- python - Python - 数组或 NumPy 操作的 OpenCV 标准化以匹配 2 个图像数组?
- python - Pandas 错误:Series 的真值不明确
- django - Django Admin:从“父”更改视图中选择外键“子”
- ios - 显示来自 firebase / Swift 的图像
- c++ - 在模板函数中推导模板函数(使用 C++ 概念)
- java - 如果未以某种格式提供,Gradle 将无法解析我的依赖项
- javascript - TypeError: val.toString 不是函数 - mysql npm