Below is a part code from a project I'm working on. I want to save the form data by an ajax call to a url /accounts/edit_profile/
(different from the form action url /orders/place_order/
). After a successful call to url /accounts/edit_profile/
, form should resubmit to orders/place_order/
but no such resubmission takes place and I have to manually click the button (place_order
) for final submission of form.
<form id="form_check" action="/orders/place_order/" method="POST" enctype="multipart/form-data">
<div class="form-row">
<div class="col form-group">
<label for="">Address line 1</label>
<input type="text" name="address_line_1" class="form-control" required>
</div>
<div class="col form-group">
<label for="">Address line 2</label>
<input type="text" name="address_line_2" class="form-control" >
</div>
</div>
<div class="form-row">
<div class="col form-group">
<label for="">City</label>
<input type="text" name="city" class="form-control" required>
</div>
<div class="col form-group">
<label for="">State</label>
<input type="text" name="state" class="form-control" required>
</div>
</div>
<div class="form-row">
<div class="col form-group">
<label for="">Pincode</label>
<input type="text" pattern="[0-9]{6}" name="pincode" class="form-control" required>
</div>
<div class="col form-group">
<label for="">Country</label>
<input type="text" name="country" class="form-control" required>
</div>
</div>
<button id="btnsubmit" type="submit" name="submit" class="btn btn-primary btn-block">Place Order</button>
</form>
The script I'm using is:
var frm = $('#form_check');
frm.submit(function() {
var r = confirm("Would you like to save this address as default address?");
if (r == true) {
$.ajax({
type: frm.attr('method'),
url: '/accounts/edit_profile/',
data: frm.serialize(),
success: function (data) {
frm.submit();
}
});
} else {
// user did not agree, do something else
}
return false;
});
Tried Soultions from these links but nothing seems to work: