JSFiddle - React, Tailwind, and code Playground
by andialbrecht
HTML
<p>This example shows how to call the sqlformat.org API using jQuery.</p>
<textarea id="sql">select * from foo</textarea><br />
<button id="format">Format statement (JSON)</button>
<button id="formatp">Format statement (JSONP)</button>
<hr />
<strong>The result:</strong><br />
<pre id="result"></pre>
JavaScript
function onSuccess(data) { $('#result').text(data['result']); }
$('#format').click(function() {
$.ajax({
url: 'http://sqlformat.org/api/v1/format',
type: 'POST',
dataType: 'json',
crossDomain: true,
data: {sql: $('#sql').val(), reindent: 1},
success: onSuccess,
});
})
$('#formatp').click(function() {
$.ajax({
url: 'http://sqlformat.org/api/v1/format',
dataType: 'jsonp',
crossDomain: true,
data: {sql: $('#sql').val(), reindent: 1},
success: onSuccess,
});
})