我想添加以下if语句,因此可以将此变量添加到post调用字符串的末尾。如果语句未出现,则看起来像这个jquery。
之后我就拥有了$("#payment-form").submit(function(event){...
//if statement here
我将它放在哪里,以便它正确启动?或者我还缺少其他东西?
if ($("#couponCode").val() == "FREEPRODUCT") {
console.log("free product 1");
var product = ";1";
console.log(product added);
}
$(document).ready(function() {
var products_ids = '<?php echo $productss; ?>';
$("#payment-form").submit(function(event) {
var fname = '<?php echo $fname; ?>';
$('#LoadingDiv').css('display', 'block');
event.preventDefault();
$.post(
"<?php echo $base_url; ?>konn_order.php?products=" + products_ids + towel_product,
$('#payment-form').serialize(),
function(data) {
var response = JSON.parse(data);
if (response.result == "ERROR") {
alert(response.message);
}
if (response.result == "SUCCESS") {
var orderid = response.message.orderId;
$('#continue_button').attr("disabled", "disabled");
// window.location.replace("<?php echo $base_url; ?>Nexgenshop.php?orderId=" + orderid);
window.location.replace("<?php echo $base_url; ?>Order-confirmation.php?orderId=" + orderid);
}
}
);
});
});