0

My setTimeout seems to be working for logging in, but not for submitting data. :

<script type="text/javascript" src="../scripts/jquery.js"></script>
<script type="text/javascript">
$.ajaxSetup({async:false});
function Validate_submit(form) {
 var Address1_input = form.address1.value;
 var Address2_input = form.address2.value;
 var City_input = form.city.value;
 var State_input = form.state.value;
 $.post('../scripts/submit_check.php', {address1php: Address1_input, address2php: Address2_input, cityphp: City_input, statephp: State_input}, 
 function(output) {
 $('#submit_msg').html(output).fadeIn(500);
 if (output == 'Submitting...') {
 var timeoutID = window.setTimeout(function () {location.reload();}, 1000);
 } else {
 $('#submit_msg').html('something went wrong').fadeIn(500);
 }
 }
 );
}

The same code works in my log-in popup window:

<script type="text/javascript" src="../scripts/jquery.js"></script>
<script type="text/javascript">
$.ajaxSetup({async:false}); 
function Validate_login(form) {
 var Email_input = form.email.value;
 var Password_input = form.password.value;
 var Rememberme_input = form.remember_me.checked;
 $.post('../scripts/login_check.php', { emailphp: Email_input, passwordphp: Password_input, rememberphp: Rememberme_input},
 function(output) {
 $('#login_msg').html(output).fadeIn(500);
 if (output == 'Logging in...') {
 var timeoutID = window.setTimeout(function () {location.reload();}, 1000);
 }
 }
 ); 
}

When I click the submit button in the submit form, it shows 'Submitting...' for a split second, but not for the whole second (like in the login-popup). Can someone help me?

asked Jul 28, 2012 at 22:52
1
  • You may want to know that async: false for ajax has been deprecated from the latest version of jQuery. Commented Jul 29, 2012 at 2:27

1 Answer 1

2

You'll probably need to cancel the actual <form>'s submission. return false from the onsubmit handler after you call Validate_submit.

answered Jul 28, 2012 at 22:55
Sign up to request clarification or add additional context in comments.

1 Comment

@wanovak: Given the function definition, I would assume that this is an onsubmit attribute and so e isn't available. (Restructuring would be a good idea, of course.)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.