$.ajax data向后台传递参数失败 contentType: "application/json"
在ajax方法设置中若不添加 contentType: "application/json" 则data可以是对象:
$.ajax({ url: actionurl, type: "POST", datType: "JSON", data: { id: nodeId }, async: false, success: function () {} });
若添加 contentType: "application/json" 则data只能是json字符串:
$.ajax({ url: actionurl, type: "POST", datType: "JSON", contentType: "application/json" data: "{'id': " + nodeId +"}", async: false, success: function () {} });
不添加 contentType: "application/json" 情况下传递多个数据:
{ "id":id[1], "name":"小明" }
此时将id和name传到后台。