Posting data to our endpoint is a breeze—just construct a JSON structure with all the form data and send it to our server using an AJAX call. Don't worry about cross-site issues; our endpoint is configured to allow posts from your page.
On the right is example jQuery code that illustrates how to pull form fields, post the data, and display the response in a textbox for testing purposes.
The code on the rights is example jQuery code that pulls fields from a form and posts the data. While jQuery is commonly used, you are free to use any framework you prefer.
We recommend providing a JSON Schema matching your front-end validation during setup. If the data posted doesn't meet the schema, our endpoint will return a 429 response code, and the response body will indicate the issue.
Though a schema isn't mandatory, it is recommended to catch data errors before they reach downstream.
var boolMap= { '': null, 'true': true, 'false': false }; var blankToNull= function (input) { var output= input.trim(); return output ? output : null; }; $(document).ready(function () { $('#send').click(function (e) { e.preventDefault(); var data= { name: { givenName: $('#givenName').val(), familyName: $('#familyName').val() }, phone: blankToNull($('#phone').val()), email: blankToNull($('#email').val()), existing: boolMap[$('#existing').val()], category: blankToNull($('#category').val()), message: blankToNull($('#message').val()) }; $.ajax({ url: 'https://api.teaglu.net/demo/patientRequest', data: JSON.stringify(data), method: 'POST', success: function { alert('Done!'); }, error: function (jqxhr, status) { alert('Failed with status ' + status); } }); }); });