Uso Fetch Api con WordPress admin-ajax.php.
let data = { action: 'my_action', } fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', body: new URLSearchParams(data) }); let data = New FormData(); data.append('action', 'my-action'); fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', body: data }); let data = { action: 'my_action', } fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });Tengo curiosidad por qué tiene un error 400? algo que extraño?
cambie su inicio de sesión de recuperación como se muestra a continuación e intente. Dado que está especificando 'Content-Type': 'json', no es necesario especificar el json.
fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: data });