H
H
Httdientee2021-12-14 16:47:45
WordPress
Httdientee, 2021-12-14 16:47:45

How to use ajax in a plugin?

I am writing a plugin, I need to add a setting to the database via ajax, but I don’t understand how I can accept ajax that I send in a file from the plugin, do I need to use a different url? Or is there another action/hook?

function add_new_url() {

        echo '<div class="wrap">
      <h1>' . get_admin_page_title() . '</h1>
      <form method="post" action="' . admin_url('admin-ajax.php') . '">
      <input type="hidden" action="action_add_new_url" value="">';

        settings_fields( $this->option_group );
        do_settings_sections( $this->page_slug );
        submit_button();

        echo '</form></div>';

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Toropov, 2021-12-25
@nefone

You need to use wp_ajax
AND add your handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question