AJAX on Front-End Button Click not working – Custom Plugin

Ok, so it’s pretty easy error – just a typo 😉

You use this line to localize your script:

wp_localize_script( 'ajax-script', 'my_foobar_client', array( 
'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );

So you use ajax_url field to store url to admin-ajax.php

But you use this line in your js file:

my_foobar_client.ajaxurl,

and there is no ajaxurl field in that object. It should be ajax_url

And here’s another typo:

$('button').click(function(){

As far as I can see, there is no button in your form. There is input of type submit with class button, so it should be:

$('.button').click(function(){

Also you’re not preventing default behavior after the click, so your form will still cause reload… This will solve that:

$('.button').click(function(e){
    e.preventDefault();
    ...