So the primary problem seems to be that my jQuery code is being completely ignored for some reason. My form is POSTing data, but it seems to be in regular key-value pairs as opposed to properly formatted JSON. The issue with what the server is receiving is exactly the same as here: How can I use JQuery to post JSON data?
My form wasn't POSTing at all until I added the 'action=' and method="POST" to my form section of my HTML, and added a 'name='value to each form input area (textboxes, dropdowns, etc.). But now that it is posting, it is using the name= 'abc' as the first value in each pair, and the value of the input as second. I've tried deleting all my jQuery to test this, and it still POSTs exactly the same way, even when there's no jQuery in the code. Below is my jQuery, designed to POST my four inputs as JSON.
<script>
$(document).ready(function() {
env1.checked = true;
$("button").click(function() {
var x = {
"apiName": $("#apinameid").val(),
"apiURL": $("#apiurlid").val(),
"environment": $("#envid").val(),
"action": $("#actionid").val()
}
$.ajax({
url: 'http://requestb.in/1kynzln1',
type: 'POST',
contentType: "application/json",
dataType: "json",
data: x,
success: function(json) {
alert(JSON.stringify(json));
},
error: function() {
alert(data);
}
});
});
});
And here is my HTML (the part which is probably relevant)
<div class="section section-primary"><div class="container"><div class="row"><div class="col-md-12"><h1 class="text-center">Akana Server Proxy Configuration Portal</h1></div></div></div></div>
<div class="section section-warning">
<div class="container">
<div class="row">
<div class="col-md-12">
<h3 class="text-left">Please enter your API's information below:</h3>
</div>
</div>
</div>
</div>
<div class="section section-warning">
<div class="container">
<div class="row">
<div class="col-md-12">
<form action="http://requestb.in/1kynzln1"method="POST"role="form">
<div class="form-group">
<label class="control-label" for="exampleInputEmail1">API Name</label>
<input name="apiName" class="form-control input-lg" id="apinameid" placeholder="Cat API" type="text">
</div>
<div class="form-group">
<label class="control-label" for="exampleInputEmail1">API URL</label>
<input name="apiURL" class="form-control input-lg" id="apiurlid" placeholder="http://cats.com/api" type="text">
</div>
<div class="form-group">
<label class="control-label">Environment</label>
<select name="environment" id="envid" class="form-control">
<option value="Dev" id="devid">Dev</option>
<option value="Stage" id="stgid">Stage</option>
<option value="Prod" id="prodid">Prod</option>
</select>
</div>
</div>
<div class="form-group"></div>
<div class="form-group">
<label class="control-label">Configuration Action</label>
<select name="action" id="actionid" class="form-control">
<option value="Add" id="add">Add a new API</option>
<option value="Remove" id="remove">Remove an API</option>
</select>
<p class="help-block">You can add or remove access to an API by configuring the proxy.</p>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</div>
</div>
Any help is very much appreciated! Thank you!