0

I am using AJAX form submit to post all values using the serialize() method so I get response in the success like this below

fullname=muthu&position=tl&status=active

This value I want to convert to array so i will try in AJAX success. How can do this? My AJAX code is here:

var candiate_form = $('#candiate_form').serialize();
$.ajax({
    type: "POST",
    url: "function.php",
    data: { candiate_form: candiate_form },
    success: function(response) {
        alert(response);
    }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Balaguru Murugan
  • 463
  • 2
  • 7
  • 21

2 Answers2

0

If you are trying to convert fullname=muthu&position=tl&status=active to an array of objects, then try this.

str = 'fullname=muthu&position=tl&status=active';
str.split('&').map(function(a, b){
    ret = {};
    ret[a.split('=')[0]] = a.split('=')[1];
    return ret;
});
rrk
  • 15,677
  • 4
  • 29
  • 45
0

I am not sure if below thing is what you are looking for.

It should be

data: candiate_form,

instead of

data: { candiate_form: candiate_form },

And in PHP, access like:

$_POST['fullname']

Jigar
  • 3,256
  • 1
  • 30
  • 51