Ajax submit result opens in admin-ajax.php

I have a plugin to submit a form via ajax.

I have this as the js:

<script type='text/javascript'>
        $(document).ready(function() {
            $('#form_id').submit(function() {
                var $form = $(this);
                $.post($form.attr('action'), $form.serialize(), function(data) {
                return false;

The HTML of the form is like:


  <form method='post' action='$action'  id='form_id'>
<ul><li><input type='text' name='dname'  placeholder='Name'  />
</li><li><input type='email' name='email' class='field-style field-split align-left'  /></li>
<input type='hidden' name='action' value='php_function'/>
<input type='submit' value='SUBMIT' />
<div id='feedback_id'></div>

There is a function php_function() to process the form input.
Every other thing is in place:

add_action('wp_ajax_php_function', 'php_function');
add_action('wp_ajax_nopriv_php_function', 'php_function');

The output is supposed to be displayed in the div with id feedback_id but it
opens and shows up in the page ‘/wp-admin/admin-ajax.php’

What am i doing wrong?

Read more here: Ajax submit result opens in admin-ajax.php

Leave a Reply

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