[英]internal server error ajax asp.net
hi i'm writing an ajax code that get data from the database server with web service but avery time i try to get data sho me Error : internal server error 嗨,我正在编写一个Ajax代码,该代码从具有Web服务的数据库服务器获取数据,但是每隔一段时间我就会尝试获取数据。报错:内部服务器错误
am doing something wrong here.. 在这里做错了..
$.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);
}
});
other side in webmethode : 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;
}
Any advises please ? 有什么建议吗? i'm blocked for 2 days
我被封锁了2天
Don't use string concatenation to pass parameters, my friend. 我的朋友,不要使用字符串连接来传递参数。 Try this:
尝试这个:
$.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);
}
});
i checked your ajax request to server is fine. 我检查了您对服务器的Ajax请求是否正常。 I think you should check your code without using method it's is working or not.
我认为您应该在不使用有效或无效的方法的情况下检查代码。 internal sever error comes when code having bugs.
代码中有错误时,将发生内部服务器错误。 check your code
检查你的代码
`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.