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

156
Views
Convert Form Data with Multiple Fields to JSON Jquery Javascript

I am having a problem converting form data post method passing through ajax. I want to convert it to JSON and I will just decode it in controller. Will pass it through ajax using post method.

Array
(
 [start_date] => 2021-10-01
 [end_date] => 2021-11-01
 [select_shop2] => 
 [checkbox_time] => on
 [start_time] => 00:30
 [end_time] => 00:30
 [todaydate] => 10/01/2021
 [batch_promo_type] => 2
 [batch_promo_rate] => 1
 [batch_promo_price] => 5
 [batch_promo_stock_qty] => 1
 [batch_purch_limit_select] => 1
 [batch_purch_limit] => 1
 [product_id] => Array
     (
        [0] => 3c1da2d798c14921b672373ba2757dd8
        [1] => fe38680795474c518dc49ba7a5c9a84f
        [2] => e140459347654876a12dbd87f84d1073
        [3] => bff038e92b414fde8fe16a420768bf2f
        [4] => fa0cb79ef920499aa918dedb7e02e225
        [5] => fdf43ab162bc4fd0bc9363033899e954
        [6] => 9403284b1eb84f5f9ef9f28bfce8d486
        [7] => 4640657c0b4a4fd9bbb139c1ae57eaee
        [8] => 29a51f916acf4ffd825f4a28667edbf5
        [9] => 343c2f955e9c4034be834378e2bdc672
    )

)

I've tried to use JSON.stringify but seems that it's not working

var form = $('#form_promoprod');
var form_data = new FormData(form[0]);
console.log(JSON.stringify(form_data));

     $.ajax({
            type: form[0].method,
            url: base_url+'promotion/Main_promotion/mc_update_promotion',
            data: form_data,
            contentType: false,   
            cache: false,      
            processData:false,
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

FormData is not just an object.

You have to use forEach loop:

const form = document.querySelector('#form_promoprod');
const formData = new FormData(form);
const object = {};
formData.forEach((value, key) => object[key] = value);
const json = JSON.stringify(object);
about 4 years ago · Juan Pablo Isaza 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!