Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Error 400 al enviar datos JSON a WordPress Admin Ajax con Fetch API

Uso Fetch Api con WordPress admin-ajax.php.

  1. Enviar datos como URLSearchParams. Esta funcionando.
 let data = { action: 'my_action', } fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', body: new URLSearchParams(data) });
  1. Enviar datos como FormData. Esta funcionando.
 let data = New FormData(); data.append('action', 'my-action'); fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', body: data });
  1. Enviar datos como JSON. NO FUNCIONA, 400 ERROR.
 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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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 });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!