[英]internal server error ajax asp.net
嗨,我正在编写一个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();`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.