ITeye博客

Ajax提交时的两个错误

jiage17 · 2018-03-29 14:37 · Jquery · Web前端 · Markdown

1、ajax提交时,总是报出500错误,找不到/Personnel/BatchInit指定的后台处理方法

$.ajax({

                    url: "/Personnel/BatchInit",

                    type: "get",

                    dataType: "text",

                    data: {cTaskGuids:ids},

                    success: function (data) {

                        alert(data);

                        location.reload(1);

                    },

                    error: function (err) {

                        alert("同步记录数据失败!");

                    }

                });

之后,添加上contentType属性后,问题解决。

$.ajax({

                    url: "/Personnel/BatchInit",

                    type: "get",

                    contentType: "text/html",

                    dataType: "text",

                    data: {cTaskGuids:ids},

                    success: function (data) {

                        alert(data);

                        location.reload(1);

                    },

                    error: function (err) {

                        alert("同步记录数据失败!");

                    }

                });

2、后台方法获得的参数为null

最初ajax提交时,type类型为post,但后台获得的参数都是null,改成get提交后,后台可以正常获取参数了。

$.ajax({

                    url: "/Personnel/BatchInit",

                    type: "get",

                    contentType: "text/html",

                    dataType: "text",

                    data: {cTaskGuids:ids},

                    success: function (data) {

                        alert(data);

                        location.reload(1);

                    },

                    error: function (err) {

                        alert("同步记录数据失败!");

                    }

                });

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。