---
title: "Ajax提交时的两个错误"
author: "jiage17"
date: "2018-03-29T14:37:06Z"
tags: []
categories: ["Web前端"]
slug: "ajax"
draft: false
lastmod: "2018-03-29T14:37:06Z"
id: 2414901
url: "https://jiage17.iteye.com/blog/2414901"
---

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("同步记录数据失败！");

                    }

                });