fill form fields with ajax response

I need to fill form fields with post_meta from an ajax response.

Everything works properly.

I could hard-code the swapping of each piece of data.meta into its form field. But that approach is not reusable.

Is there a way to loop through the data.meta instead?

In some cases, there may not be meta for all the form fields. And in some cases, there may be meta that is not applicable to the form.



    success: function (data) {

        if (data.status === 'success') {


            $.each(data.meta, function(key,value) {

                  alert(key + '---' + value[0]); 

                  // if key is a form element, add the value to that element

                  // if key is a form element that is a select dropdown, 
                  //  then mark that option as selected



Read more here: fill form fields with ajax response

Leave a Reply

Your email address will not be published. Required fields are marked *