代码之家  ›  专栏  ›  技术社区  ›  user13286

反应-使用wp_mail发送电子邮件

  •  1
  • user13286  · 技术社区  · 6 年前

    jQuery.ajax({
        type: 'POST',
        url: 'admin-ajax.php',
        data: { action: 'send_form' }
    }).done(function(response) {
        alert(response);
    });
    

    但是,由于我没有在React应用程序中使用jQuery,所以我使用 fetch

    const res = await fetch('admin-ajax.php', {
        method: 'POST',
        body: JSON.stringify(this.state.values),
        headers: {
            "Content-Type": "application/json"
        }
    });
    

    我的问题是,我怎样才能把行动传下去, send_form 在我的回应电话里?

    1 回复  |  直到 6 年前
        1
  •  3
  •   Anurag Srivastava    6 年前

    你可以附加到 body

    body: JSON.stringify({...this.state.values, 'action': 'send_form'})