首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用AJAX的注册表单-在Wordpress中提交

使用AJAX的注册表单-在Wordpress中提交
EN

Stack Overflow用户
提问于 2018-10-11 07:13:29
回答 1查看 124关注 0票数 0

解决这个问题让我有些头疼。我有一个Wordpress / Woocommerce注册表单,它触发几个动作才能工作。除了这些操作之外,我还想将表单数据发送到CRM。它独立工作得很好,但不能协同工作。

下面是表单标记:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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放在一起?

EN

回答 1

Stack Overflow用户

发布于 2018-10-11 08:25:57

我做了一些微妙的改变。另外,确保您已经安装了jQuery。

试试这个,看看它是否有帮助:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52750000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档