Clean jquery post response
$10-30 USD
Paid on delivery
I need addition to the below jQuery response that will cleanly clear sent post data and clear input values so that additional request can be made cleanly.
In addition I require the code required to trigger both a successful and failed response to the form post request from the /[login to view URL] file.
Here is the form to work with:
<form id="trans-form">
<select name="make" id="make" required >
<option value="" class="first_option" selected="selected" disabled>Select Asset</option>
<option value="1">car</option>
<option value="2">truck</option>
</select>
<input type="text" name="model" placeholder="Model" value="" readonly />
<input type="number" name="amount" placeholder="Transfer Amount" required />
<input type="text" name="trans-address" id="trans-address" placeholder="address" required />
<input type="submit" name="trans_sub" value="SUBMIT" />
<div id="fal" class="hid-fal">There has been an error. Please re-check your input and try again.</div>
<div id="suc" class="hid-suc">Please check your email to authorise request.</div>
<div id="proc" class="hid-proc">Processing......</div>
</form>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#make').change(function() {
var balance = jQuery('#make').val();
switch(balance)
{
case '1':
jQuery('[name=model]').val('ford');
break;
case '2':
jQuery('[name=model]').val('nissan');
break;
default:
jQuery('[name=model]').val('all');
}
});
jQuery('form#trans-form').on('submit', function(e) {
jQuery('#fal').hide();
jQuery('#suc').hide();
jQuery('#proc').show();
[login to view URL]('/[login to view URL]', jQuery(this).serialize(), function (data) {
// 'data' contains the response from the request
jQuery('#proc').hide();
jQuery('#fal').hide();
jQuery('#suc').show();
// need function here that cleanly clears form inputs and clears all cached information from post request/response
}).error(function() {
// This is executed when the call failed.
jQuery('#proc').hide();
jQuery('#suc').hide();
jQuery('#fal').show();
// need function here that cleanly clears form inputs and clears all cached information from failed post request/response
});
[login to view URL]();
});
});
</script>
Project ID: #15651382