title: Send JavaScript object to web server call via jQuery - what is the correct way?
body: <p>I'm trying to send JSON data to my web server via jQuery and I'm running into an error.
  Uncaught TypeError: Cannot use 'in' operator to search for 'context' in {"id":45,"isRead":true}</p>
  
  <p>code I am testing:  </p>
  
  <pre><code>var obj = {};
  obj.id = 45;
  obj.isRead = true;
  var data = JSON.stringify(obj);
  var url = "/notification/read"
  $.ajax(url, data, 'application/json', function() {
      // code remove notification from the DOM
      });
  });
  </code></pre>
  
  <p>Is there a better or more correct way to do this? Not sure if I'm getting the params right on the $.ajax call either.</p>
  
  <p><strong>UPDATE</strong><br>
  code I got to work  </p>
  
  <pre><code>var obj = {
      id: 45,
      isRead: true
  };
  var json = JSON.stringify(obj);
  var url = "/notification/read"
  $.ajax({ url: url, 
           type:'POST', 
           contentType: 'application/json', 
           data: json, 
           success: function(data, textStatus) {
              // do stuff
           }
  });
  </code></pre>
  
  <p>My server was expecting JSON data POSTed as application/json. So was I wrong in thinking I needed all these variables? without these it was sent as a GET and was application/x-www-form-urlencoded. Without the stringify it also didn't work.</p>