I am working on a site where I need to do various operations in the same page..using 3 forms..one by one. ..Similar to unlockninja.com
The issue is When I submit the one form.. I am getting the other form's layout in response... I am replacing the first form by second inside the same div.All forms have different IDs and I am using JQuery AJAX to process the forms using 3 different PHP files.
Problem is : It works well only for 2 consecutive forms... but on clicking 3rd time... the page refreshes and stops processing further...i.e. The page does not update without the refresh... it is calling refresh and goes back to the previous form... rather than going to the next form. Totally I have 3 forms ... on submit of each form...some PHP db operations happen... after these operation...the php script echos the html layout that is to be loaded to the div area of HTML...inside which I am placing the form.
The db operations are happening...but the page update in not working after 2 forms.
<script type="text/javascript">
$(function(){
$("#orderForm").submit(function(e){
e.preventDefault();
var service_id = $("#service_id").val();
var imei = $("#imei").val();
var email = $("#email").val();
var phone = $("#phone").val();
var api_key = $("#api_key").val();
var comments = $("#comments").val();
var dataString = 'service_id='+ service_id + '&imei=' + imei + '&email=' + email + '&phone=' + phone + '&api_key=' + api_key+ '&comments=' + comments;
if(imei.length != 15 || isNaN(imei)){
$("#message_ajax").html('<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>Please enter a valid IMEI number. Type *#06# on your phone.</strong> </div>');
return false;
}
$.ajax({
type: "POST",
url: "order_processor.php",
data: dataString,
success: function(data) {
$("#service_area").html(data).show();
//$('#orderForm').unbind('submit').submit()
}
});
});
});
</script>
<script type="text/javascript">
$(function(){
$("#paymentForm").submit(function(e){
e.preventDefault();
$("#service_area").html("Processing Payment...Please wait").show();
$.ajax({
url: "payment_processor.php",
success: function(data) {
$("#service_area").html(data).show();
//$('#paymentForm').unbind('submit').submit()
}
});
});
});
</script>
<script type="text/javascript">
$(function(){
$("#goBackForm").submit(function(e){
e.preventDefault();
$("#service_area").html("All is well...getting back").show();
$.ajax({
url: "all_done_processor.php",
success: function(data) {
$("#service_area").html(data).show();
//$('#goBackForm').unbind('submit').submit()
}
});
});
});
</script>
I think the issue is related with e.preventDefault() .. I tried resolving that by
$('#orderForm').unbind('submit').submit()
Still... no success.