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

172
Views
Single ajax for image data and other serialized data

I want to send data2 variable to my PHP script using but with below given code i am getting empty array of $_POST in my controller

 var data2 = {
    donation: $("#donationform").serialize(),
    allocation: $("#allocationform").serialize(),
    allocationerrors: { msg: validation() },
    datatoform: new FormData(this)
};
$.ajax({
    url: url,
    type: "POST",
    dataType: "JSON",
    data: data2,
    processData: false,
    contentType: false,
    success: function(data, status) {},
    error: function(xhr, desc, err) {}
});
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem is because you cannot send binary FormData in an object. You need to do it the other way around; ie. append the data to the FormData object and send that in the request. Try this:

var formData = new FormData(this);
formData.append('donation', $("#donationform").serialize());
formData.append('allocation', $("#allocationform").serialize());
formData.append('allocationerrors', JSON.stringify({ msg: validation() }));

$.ajax({
  url: url,
  type: "POST",
  data: formData,
  processData: false,
  contentType: false,
  success: function (data, status) {
  },
  error: function (xhr, desc, err) {
  }
});
about 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!