簡體   English   中英

內部服務器錯誤ajax asp.net

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM