2 回答
TA贡献2016条经验 获得超9个赞
为您的 expressJS 应用程序的请求设置JSON正文解析器中间件。
const bodyParser = require('body-parser');
app.use(bodyParser.json())
并且在 AJAX 请求中,使contentType成为application/json而不是application/x-www-form-urlencoded; charset=UTF-8'.
$.ajax({
contentType: 'application/json',
type: "POST",
url: '/user/sell',
data: data,
success: function(data) {
console.log('Call was successful');
}
});
TA贡献1811条经验 获得超6个赞
假设这是您要发布的数组列表。
object[] Obj = new object[1];
Obj [0] = "value1"
Obj [1] = "Value2"
Obj [3] = {"CollectionValue1, CollectionValue2"}
$.ajax({
url: '../Controller/MethodName',
type: 'post',
datatype: 'json',
async: false,
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ ControllerParameterName: Obj }), <!-- Obj is your Array -->
success: function (data) {
alert(data.Response);
}
});
添加回答
举报