ajax contentType

1.不使用contentType: “application/json”则data可以是对象

$.ajax({
  url: actionurl,
  type: "POST",
  datType: "JSON",
  data: { id: nodeId },
  async: false,
  success: function () {}
});

2.使用contentType: “application/json”则data只能是json字符串

$.ajax({
  url: actionurl,
  type: "POST",
  datType: "JSON",
  contentType: "application/json"
  data: "{'id': 123}",
  async: false,
  success: function () {}
});  

或者

$.ajax({
  url: actionurl,
  type: "POST",
  datType: "JSON",
  contentType: "application/json"
  data: JSON.stringify({'id': 123}),
  async: false,
  success: function () {}
});  

 

posted @ 2018-03-27 21:59  雾以泪聚rx  阅读(150)  评论(0编辑  收藏  举报