0

The web service accepts application/json, but $.ajax() with dataType : 'json' set just tries to send data as application/x-www-form-urlencoded. What's the trick here?

Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • Checkout this answer http://stackoverflow.com/a/18701357/1370442 notice you need to set contentType as well as dataType ;o) – Luke Baughan Sep 24 '14 at 17:33

1 Answers1

2

dataType: 'json' specifies that jQuery expects JSON back from the server (see docs). In order to specify that you are sending JSON, you need to add contentType: "application/json".

Furthermore, jQuery cannot convert an object into JSON for you. If you are passing any object to data, you need to stringify it yourself:

data: JSON.stringify(dataObject);
Community
  • 1
  • 1
Stryner
  • 7,288
  • 3
  • 18
  • 18