Commit c5287c3
Changed files (2)
js/trax_input.js
@@ -1,3 +1,36 @@
$(document).ready( function() {
+ // set date to today's date for convenience
$('#inputDate').val(new Date().toJSON().slice(0,10));
+
+ var request;
+ $('#car_input').submit(functon(event){
+
+ // abort if request is not empty (aka something is already pending)
+ if (request) { request.abort(); }
+ var $form = $(this);
+ var $inputs = $form.find("inputDate, inputAmount, inputPrice, inputOdometer"); // TODO refactor
+ var serializedData = $form.serialize(); // serialized inputs
+
+ // disable inputs during ajax request
+ $inputs.prop("disabled", true);
+
+ // ajax request to input_process.php
+ $.post('/input_process.php', serializedData, funciton(response) {
+ console.log("Response: "+ response);
+ });
+
+ // callback on success
+ request.done(function (response, textStatus, jqXHR){
+ console.log("Horray");
+ });
+
+ // callback regardless of success
+ request.always(function () {
+ $inputs.prop("disabled", false);
+ });
+
+ // prevent default posting of form
+ event.preventDefault();
+
+ });
})
input.php
@@ -3,7 +3,7 @@
<div class="row">
<?php include 'input_process.php'?>
<form class="form-horizontal col-sm-8 col-sm-offset-2" role="form"
- action="" method="POST">
+ action="" method="POST" id="car_form">
<div class="form-group">
<label for="inputDate" class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">