Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

jQuery - submit form before ajax call?

Hi,
I need my sendTracking function to submit a form #update_order before executing my process_order_update.php
All works fine except I don't receive an alert back "Updated Order Details Sent to Customers with Tracking Number"?

If I comment out  $('form#update_order').submit(); then I receive the alert?

Any ideas on how it should be coded would be appreciated.

// view_order_update.php 
<input type="button" class="button_sml orange" onclick="sendTracking();" value="Send Tracking Details">

<script>
    var sendTracking= function() {
        
		$('form#update_order').submit();
		
		var answer = confirm('This will send an email to the customer with their Delivery Tracking Number.');
        if(answer==true) {
			 
			 var updateURL = "/process_order_update.php?order_id="+<?php echo $order_id; ?>;
			 $.ajax({
        		 url: updateURL, success: function(data){
				alert("Updated Order Details Sent to Customers with Tracking Number");
				}
			 });
			 
        }
    }
</script>


<?php //process_order_update.php 
...
..


echo "Updated Order Details Sent to Customers with Tracking Number";

?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of vr6r
vr6r

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs
sabecs

ASKER

Thanks for your help, much appreciated.
It still looks like it's not submitting the form?

<form action="view_upd_order.php" method="POST" name="update_order" id="update_order">

should this line now be?
$.post($('form#update_order').attr('view_upd_order.php'), $('#form#update_order').serialize(), function(){
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs

ASKER

Thanks vr6r, that is perfect...