Quick Order Form
jQuery( document ).ready(function() { var $j = jQuery.noConflict(); // Variable to hold request var request;
var ProductURL = window.location.href $j('#URL').val(ProductURL);
$j( "a.close-btn" ).click(function() { $j('#error-text').slideUp(); });
// Bind to the submit event of our form $j("#foo").submit(function(event){
// Abort any pending request if (request) { request.abort(); } // setup some local variables var $form = $j(this);
// Let's select and cache all the fields var $inputs = $form.find("input, select, button, textarea");
// Serialize the data in the form var serializedData = $form.serialize();
// Let's disable the inputs for the duration of the Ajax request. // Note: we disable elements AFTER the form data has been serialized. // Disabled form elements will not be serialized. $inputs.prop("disabled", true);
// Fire off the request to /form.php request = $j.ajax({ url: "https://script.google.com/macros/s/AKfycbxIiJuIKO5S4YCDWzkYM97zszkZ-blvkRj6wa_owPtwLR8J6Jfn/exec", type: "post", data: serializedData });
// Callback handler that will be called on success request.done(function (response, textStatus, jqXHR){ // Log a message to the console console.log("Hooray, it worked!"); console.log(response); console.log(textStatus); console.log(jqXHR); window.location = 'https://decorations.pk/orderconfirm/'; });
event.preventDefault(); // Callback handler that will be called on failure request.fail(function (jqXHR, textStatus, errorThrown){ // Log the error to the console console.error( "The following error occurred: "+ textStatus, errorThrown ); alert('Kindly submit your order again'); });
// Callback handler that will be called regardless // if the request failed or succeeded request.always(function () { // Reenable the inputs $inputs.prop("disabled", false); });
// Callback handler that will be called regardless // if the request failed or succeeded request.always(function () { // Reenable the inputs $inputs.prop("disabled", false); //$j('#error-text').fadeIn();
});
// Prevent default posting of form j$( "#error-text" ).slideDown(); event.preventDefault(); });
});