首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内部服务器错误ajax asp.net

内部服务器错误ajax asp.net
EN

Stack Overflow用户
提问于 2018-08-02 23:41:43
回答 2查看 32关注 0票数 0

您好,我正在编写一段ajax代码,它使用web服务从数据库服务器获取数据,但每次我尝试获取数据时都会出错:内部服务器错误

我在这里做错了什么..

代码语言:javascript
复制
$.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中的另一面:

代码语言:javascript
复制
        [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;
        }

有什么建议吗?我被封了两天

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-02 23:51:47

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

代码语言:javascript
复制
$.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);
                }
            });
票数 1
EN

Stack Overflow用户

发布于 2018-08-03 00:01:37

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

代码语言:javascript
复制
`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();`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51657558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档