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

256
Views
Wordpress ajax request in pure javascript (where to put action?)

WordPress ajax request in jquery.

The ajax request in jquery works but I'm trying to use pure JavaScript.

How can I turn this code into pure javascript?

$('#camitonContactForm').submit(function(event){
event.preventDefault();
    
isValidationOn = true;
validateInputs();

let formaction =   $('#camitonContactForm').data('url');
let forminput =   $('#camitonContactForm').serialize();

let noncecheck = $('#camitonContactForm').data('nonce'); ;
let formdata = new FormData;

formdata.append('action', 'contact_message');
formdata.append('nonce', noncecheck);
formdata.append('contact_message',forminput);

$.ajax(formaction, {

  type:'POST',
  data:formdata,
  processData: false,
  contentType:false,

  success: function(res){

  
  },

  error: function(err){
     alert(err.responseJSON.data);
  }

});

Here I tried to write it in pure javascript but it doesn't work.

 form.addEventListener('submit', (e) => {
  e.preventDefault();
  isValidationOn = true;
  validateInputs();


   //form action
  let formwrapper = document.getElementById('camitonContactForm');
  let formaction = formwrapper.getAttribute('data-url');
  //form nonce
  let noncecheck = formwrapper.getAttribute('data-nonce');
  //form
  let forminput =  serialize(formwrapper);

  
  var formdata = new FormData(form);

  
 /*
  formdata.append('action', 'contact_message');
  formdata.append('nonce', noncecheck);
  formdata.append('contact_message',forminput);
 */
  let  ajax = new XMLHttpRequest();

  ajax.open("POST",  formaction, true);
  ajax.onreadystatechange = function() {
    if(ajax.responseText == 4 && ajax.status == 200){
      if(ajax.responseText == "success"){
          
      }else{
          statusSection.innerHTML = ajax.responseText;
          btnsection.disabled = false;
          alert('well something wrong');
      }

    }
  }
  ajax.send(formdata);

});

the serialize funcion i found on this link below form serialize javascript (no framework)

about 4 years ago · Juan Pablo Isaza
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!