Ajax is not working in wordpress admin

iam a beginner level wordpress developer ..now at halfway on creating newsletter plugin administration panel. In this admin panel iam using jquery.post ajax for submitting the form.Unfortunately the ajax is not working. But i am using the same wordpress ajax in my site’s front end for taking email id from users and it’s working fine.

i have verified all the code..unfortunately i couldn’t find what’s wrong in my code.

Read More

my jquery script

jQuery(document).ready(function(){  

   jQuery("#saveValue").click(function(){
       jQuery("#apiData").submit();

   });


   jQuery("#apiData").submit(adminSettingSave('#apiData'));

});

function adminSettingSave(secti){
    return function(){
        var form_data = jQuery(secti).serialize();
        form_data += '&action=settings-save';
        alert(secti);
         jQuery.post(ajaxurl, form_data, function (response) {
             alert(response);

         });



    }
} 

wordpress function

add_action( 'wp_ajax_settings-save', 'settings_save');
function settings_save()
{

    die();
}

but this is not working, instead of this its reloading the page
please help me

Related posts

Leave a Reply

1 comment

  1. How about change

     jQuery("#apiData").submit(adminSettingSave('#apiData'));
    

    to

     jQuery("#apiData").submit(function() {adminSettingSave('#apiData'); return false});
    

    I think your page reload because your submit event initialization do not work. The submit event listener function also need returning false to prevent default form action.