because the page is automatically submitted to the / apply processing page when the form is submitted, the JSON data
is returned, so the redirection is redirected to / applysuccess
using ajax. However, when the data is not submitted successfully, when you get the data, you see null
ask for help
//ajax
$.ajax({
type: "post",
url: "/apply",
async: true,
dataType: "json",
data: $("-sharpsub").serialize(),
success: function (data) {
$("-sharpsub").attr("method", "GET").attr("action", "/applysuccess");
$("-sharpapply").html("<h3>" + data.message + "</h3>");
$(".count").html(" " + data.count + " ");
}
});
< form action= "/ apply" method= "post" id= "sub" >
<div class="form-group fl col-md-4">
<input class="form-control" name="first_name" placeholder="first name" required>
<input class="form-control" name="last_name" placeholder="last name" required>
</div>
<div class="form-group fl col-md-4">
<input class="form-control" name="position_id" placeholder="position id" required>
<input class="form-control" name="years_experience" placeholder="years experience" required>
</div>
<div class="form-group fl col-md-4">
<input class="form-control" name="expertise" placeholder="expertise" required>
<button id="applyBtn" type="submit" class="btn btn-primary btn-lg">Apply for Job NOW</button>
</div>
</form>