Here is an example on how you can send a JSON object to a server with jQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> var data = { "name": "Neugebauer", "prename": "Benny", "age": 24, "likes": [], "device": "Laptop" }; jQuery(document).ready(function($){ $.ajax({ type: "POST", url: "https://www.bennyn.de/rest-service/something", data: typeof data == "string" ? data : JSON.stringify(data || {}), dataType: "json", contentType: "application/json; charset=utf-8", success: function(data, textStatus, jqXHR){ console.log('OK:' + data); }, error: function(data, textStatus, jqXHR){ console.log('ERROR:' + data); } }); }); </script> |