$.post() doesn't send data as json but as x-www-form-urlencoded instead

后端 未结 4 1137
傲寒
傲寒 2020-12-14 00:11

This one is really weird. I\'ve multiple $.post() in the code but there is one dunno why sends the json parameters as x-www-form-urlencoded instead

4条回答
  •  旧巷少年郎
    2020-12-14 00:30

    this also works for me

    $.ajax({
      url: "mydomain.com/url",
      type: "POST",
      dataType: "xml/html/script/json", // expected format for response
      contentType: "application/json", // send as JSON
      data: JSON.stringify(data),
    
      complete: function() {
        //called when complete
      },
    
      success: function() {
        //called when successful
     },
    
      error: function() {
        //called when there is an error
      },
    });
    

提交回复
热议问题