简体   繁体   English

WordPress REST API自定义表单提交-React

[英]Wordpress REST API custom form submit - React

Wanted to POST custom form data through Wordpress API using ReactJS. 想要使用ReactJS通过Wordpress API发布自定义表单数据。 Like we use AJAX in Wordpress using something like 就像我们在Wordpress中使用AJAX一样

jQuery.ajax({
        type: 'POST',
        data: {
            action  : 'formData',  // wp_ajax_nopriv_formData
            data    : formData  // data from form
        },
        url: ajaxurl  // admin.php
    }).done(){...}

Wordpress and React are not on the same domain. WordPress和React不在同一个域中。 I am using wp-apiv2 . 我正在使用wp-apiv2

  • Are there any working examples regarding this? 有任何可行的例子吗? (React or Angular) (反应式或角度式)
  • How can I use OAuth to get to admin.php in Wordpress to submit my form? 如何在Wordpress中使用OAuth进入admin.php提交表单?

I wanted to know how can I use WP-API to submit custom form through React (as front end) as an external call eg 我想知道如何使用WP-API通过React(作为前端)作为外部调用来提交自定义表单,例如

abc.com - Wordpress domain with wp-api installed xyz.com - ReactJS implemented website - from here I will call all the API's endpoints abc.com-安装了wp-api的Wordpress域xyz.com-ReactJS实现的网站-从这里我将调用所有API的端点

Using jsx what about: 使用jsx怎么办:

<form onsubmit={()=>{
    jQuery.ajax({
        type: 'POST',
        data: {
            action  : 'formData',  // wp_ajax_nopriv_formData
            data    : formData  // data from form
        },
        url: ajaxurl  // admin.php
    }).done(){...}
}}>
<input type='text' value='hello'></input>
<button type="submit">submit</button>
</form>

Or with just React: 或仅使用React:

'use strict';

React.createElement(
    'form',
    { onsubmit: function onsubmit() {
            jQuery.ajax({
                type: 'POST'
            });
        } },
    React.createElement('input', { type: 'text', value: 'hello' }),
    React.createElement(
        'button',
        { type: 'submit' },
        'submit'
    )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM