Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!