Jquery $ajax 函数 returns C# 中的 500 内部服务器错误
Jquery $ajax funtion returns 500 Internal Server Error in C#
单击按钮时,我在页面 load.But 后将一些数据传递到 .cs 文件 我在调用 ajax 函数时遇到 500 内部服务器错误。
Ajax函数,
$.ajax({
type: "POST",
url: "Home.aspx/getSelectedData",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
//async: true,
调用函数,
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public List<pageResult> getSelectedData(string search_value)
{}
我收到以下错误,
**POST http://localhost:4519/Home.aspx/getSelectedData 500 (Internal Server Error)**
contentType
是您要发送的数据类型,因此 application/json
;
默认为application/x-www-form-urlencoded; charset=UTF-8
。
如果使用application/json
,则必须使用JSON.stringify()才能发送JSON对象。
JSON.stringify() 将 javascript 对象转换为 json 文本并将其存储在字符串中。
$.ajax({
type: "POST",
url: "Home.aspx/getSelectedData",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
将您的 ajax 类型更改为 get
$.ajax({
type: "get",
url: "Home.aspx/getSelectedData",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
像这样使用.cs文件,
[WebMethod]
public static List<pageResult> getSelectedData(string search_value)
{}
对于 ajax 在 aspx 中调用,您应该将方法定义为 Static 然后它才会为您工作。
单击按钮时,我在页面 load.But 后将一些数据传递到 .cs 文件 我在调用 ajax 函数时遇到 500 内部服务器错误。
Ajax函数,
$.ajax({
type: "POST",
url: "Home.aspx/getSelectedData",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
//async: true,
调用函数,
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public List<pageResult> getSelectedData(string search_value)
{}
我收到以下错误,
**POST http://localhost:4519/Home.aspx/getSelectedData 500 (Internal Server Error)**
contentType
是您要发送的数据类型,因此 application/json
;
默认为application/x-www-form-urlencoded; charset=UTF-8
。
如果使用application/json
,则必须使用JSON.stringify()才能发送JSON对象。
JSON.stringify() 将 javascript 对象转换为 json 文本并将其存储在字符串中。
$.ajax({
type: "POST",
url: "Home.aspx/getSelectedData",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
将您的 ajax 类型更改为 get
$.ajax({
type: "get",
url: "Home.aspx/getSelectedData",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
像这样使用.cs文件,
[WebMethod]
public static List<pageResult> getSelectedData(string search_value)
{}
对于 ajax 在 aspx 中调用,您应该将方法定义为 Static 然后它才会为您工作。