Reputation: 58
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
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 :
[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
Upvotes: 0
Views: 49
Reputation: 119
i checked your ajax request to server is fine. 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();`
Upvotes: 0
Reputation: 2245
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);
}
});
Upvotes: 1