Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am writing a plugin with dynamic no. of input fields in form. To submit form via ajax, I have used jquery serialize() function.

$(".submit").submit(function( event ) {
        event.preventDefault();
        var data = {
            action: 'wpaie_ajax_action',
            operation: 'import',
            importData: $(this).serialize()
//do some operation
        };
        $.post(ajaxurl, data, function(response) {

        });
    });

Ajax is working fine and data is also serialized but I am not able understand how to read the form input fields.

If I am using echo $_POST["importData"], it is showing me serialized data but what should be the correct way to read that serialized data.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Provided that your server receives data in the form of a string which it should if you're using the jQuery serialize() function.

It will be something like:

name1=value&name2=value&name3=value

You just need to parse the string into an array as follows:

$parameters = array(); parse_str($_GET, $parameters);

See the following for more information: http://www.php.net/manual/en/function.parse-str.php

share|improve this answer
    
Thanks for the help!!! I will use parse-str to parse the values. Thanks –  user2791285 Jul 13 at 14:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.