解决这个问题让我有些头疼。我有一个Wordpress / Woocommerce注册表单,它触发几个动作才能工作。除了这些操作之外,我还想将表单数据发送到CRM。它独立工作得很好,但不能协同工作。
下面是表单标记:
<form id="bc_post-register" method="post" class="register">
<?php do_action( 'woocommerce_action_one' ); ?>
<input placeholder="E-Mail*" type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
<input type="submit" class="woocommerce-Button button" name="register" value="Kostenlos einschreiben" />
</form>
<?php do_action( 'woocommerce_action_two' );?>
<?php do_action( 'woocommerce_action_three' );?>
下面是我的AJAX:
jQuery(document).ready(function(event) {
jQuery('#bc_post-register').submit(ajaxSubmit);
function ajaxSubmit() {
var ConvForm = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "https://app.crm.com/directory/id/action",
data: ConvForm,
success: function(data) {
console.log("has been sent");
}
});
return false;
}
});
它们都工作得很好,但并不是在一起。我如何把拼图和我的AJAX放在一起?
发布于 2018-10-11 08:25:57
我做了一些微妙的改变。另外,确保您已经安装了jQuery。
试试这个,看看它是否有帮助:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(event){
$('#bc_post-register').submit(function(event){
event.preventDefault(); //Prevents your from submitting/refreshing.
var string = $('#bc_post-register').serialize();
$.ajax({
type: "POST",
url: "https://app.crm.com/directory/id/action.php", //added the .php
data: string,
dataType: 'json', //The response needs to be a json formatted string.
cache: false,
success: function(response){
console.log('This is your response: ' + response);
}else{
console.log('There was a problem submitting your ajax.');
}
});
});
});
</script>
https://stackoverflow.com/questions/52750000
复制相似问题