ajax asp.net内部服务器错误



hi我正在写一个ajax代码,通过web服务从数据库服务器获取数据,但每次我都试图获取数据错误:内部服务器错误

我在这里做错了什么。。

$.ajax({
type: "POST",
url: "CreerEquipe.aspx/GetFrmtionShema",
data: "{'id':'" + parseInt(id) + "','formation':'4-4-2'}",
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function (res) {
alert(res.d);
$('.formation').html(res.d);
//alert(schema);
//$("#TotalDEF").html("(" + Count + "/5)");
},
error: function (xhr, status, error) {
alert('Error : ' + error);
}
});

webmethode中的另一面:

[WebMethod]
[ScriptMethod]
public static string GetFrmtionShema(int id,string formation)
{
string data = "";
ConGeters Config = new ConGeters();
Config.Cmd = new SqlCommand("select * from tbl_Formation where id_formation = @id", Config.con);
Config.Cmd.Parameters.AddWithValue("@id", id);
//Config.Cmd.CommandType = CommandType.StoredProcedure;
Config.Open();
Config.Dr = Config.Cmd.ExecuteReader();
while (Config.Dr.Read())
{
data = Config.Dr[4].ToString();
}
Config.Close();
Config.Dr.Close();
return data;
}

有什么建议吗?我被阻止2天

朋友,不要使用字符串串联来传递参数。试试这个:

$.ajax({
type: "POST",
url: "CreerEquipe.aspx/GetFrmtionShema",
data: JSON.stringify({ id: parseInt(id), formation: '4-4-2' }),,
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function (res) {
alert(res.d);
$('.formation').html(res.d);
//alert(schema);
//$("#TotalDEF").html("(" + Count + "/5)");
},
error: function (xhr, status, error) {
alert('Error : ' + error);
}
});

我检查了您对服务器的ajax请求是否正常。我认为你应该在不使用方法的情况下检查你的代码——它是否有效。当代码出现错误时,会出现内部服务器错误。检查您的代码

`ConGeters Config = new ConGeters();
Config.Cmd = new SqlCommand("select * from tbl_Formation where id_formation = @id", Config.con);
Config.Cmd.Parameters.AddWithValue("@id", id);
//Config.Cmd.CommandType = CommandType.StoredProcedure;
Config.Open();
Config.Dr = Config.Cmd.ExecuteReader();
while (Config.Dr.Read())
{
data = Config.Dr[4].ToString();
}
Config.Close();
Config.Dr.Close();`

最新更新