Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
ajax_url is not defined. Any ideas on how to fix?

I have tried going through all of the posts to do with the URL not being defined however none have fixed it.

My code in index:

   wp_enqueue_script('BbingoAppG', plugin_dir_url(__FILE__) . 'js/formProcess.js', array ( 'jquery' ), 0.1, false);
   wp_localize_script( 'BbingoAppG', 'bbingo2_obj', array('ajax_url' => admin_url( 'admin-ajax.php' ) ));

Then lower down:

add_action( 'wp_ajax_bsetter_ajax_request', 'bsetter_ajax_request' );
add_action( 'wp_ajax_nopriv_bsetter_ajax_request', 'bsetter_ajax_request' );

The function being called:

function submitCard(newPartner){
         alert(newPartner);
         jQuery.ajax({
          url: ajax_url, // Since WP 2.8 ajaxurl is always defined and points to admin-ajax.php
          data: {
              'action':'bsetter_ajax_request', // This is our PHP function below
              'gamecard': JSON.stringify(newPartner)
          },
          success:function(data) {
      // This outputs the result of the ajax request (The Callback)
                alert("Successfully added a partner");
              jQuery("#newPForm").text(data);
          },
          error: function(errorThrown){
              window.alert(errorThrown);
          }
      });

}

Any help would be greatly appreciated :)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

if ajax url is not defined it might be because your JS script is called before it is declared. Make sure to add your JS in your functions.php with the wp_register_script hook.

If you want a quick fix or test the ajax endpoint, the base url is /admin-ajax.php?action=bsetter_ajax_request.

function.php

// exemple
function my_enqueue_scripts()
{
    wp_register_script( 'myscript', get_template_directory_uri() . 'js/myscript.js' );
}

add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda