WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In one file (test_ajax.php) I have a which on change loads another page (registration_form_race_type.php) with a short message via jQuery Ajax(). It works fine when "test_ajax.php" is accessed via its absolute URL which is :

But amazingly enough, the Ajax functionality ceases to work if the exact same page "test_ajax.php" is accessed via its WordPress address which is :

I insist these both URLs point to the same two PHP files.

Here is the code of "test_ajax.php" :

Template Name: Page Test Ajax 01
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
    <script type="text/javascript">
        jQuery(function () {    
            jQuery('#event_id_from_list').change(function() {       
                var event = jQuery("#event_id_from_list").val(); 
                var data = "event_id=" + event;         
                    url: 'registration_form_race_type.php', 
                    type: 'GET',
                    data: data,
                    success: function(data){ 
    <select class='required' type="text" name="event_id_from_list" id="event_id_from_list" />
        <option value='Paris'>Paris</option>
        <option value='London'>London</option>
        <option value='Rome'>Rome</option>
    <div id='div_race_type' class='section'>            
        <?php require_once('registration_form_race_type.php'); ?>           

And the code of the page called via Ajax, "registration_form_race_type.php" :

<?php if (isset($_GET['event_id'])) echo 'you selected '.$_GET['event_id']; ?>
share|improve this question
Please follow these steps to use AJAX. – toscho Mar 15 '13 at 6:33
@toscho: thanks, I read this but is it not for plugins only (since some steps involve adding stuff in plugin file)? – drake035 Mar 15 '13 at 14:02
Your AJAX callback function can load any file from any theme or plugin. But the URL should be the one WordPress offers. – toscho Mar 15 '13 at 14:06
up vote 0 down vote accepted

I advice to use the wp built-in ajax. it allows avoiding many problems and brings many benefits.

an example that I wrote to illustrate the 2 approches:

Dynamically changing navigation links (next and previous) via AJAX

I am here to provide with explanations

good luck

share|improve this answer
Thanks. I think the WordPress way of doing Ajax is awfully complicated (I mean compare to jQuery: load(page.php), done! For WordPress you need to follow tutorials.. – drake035 Mar 23 '13 at 16:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.