Passing jQuery value using Ajax to a page template

I have the following jQuery code:-

jQuery('.fancymember').on('click', function() {
    var member = jQuery(this).parent('div').parent('div').find('.test').val();
    var dataString = 'member="+ member;
    jQuery.ajax({
      type: "POST",
      url: "http://website.dev/wp-content/themes/website/template-about.php",
      data: dataString,
      dataType: "text',
      success:function(event){
      //    alert(member);
            jQuery('#test2').val(member);
      }
    });

});

I want to pass the value ‘member’ to use in a WordPress page template, I am trying to retrieve the value as follows:-

<?php $testing = $_POST['member']; ?>

But when I do:-

<?php var_dump($testing); ?>

$testing is NULL, any ideas what I am doing wrong?

I’ve tried to pass it to the page name as well but that didn’t work (url: "get-to-know-us",)

Okay just checked in firebug console and I get the following error:-

Fatal error: Call to undefined function get_header() in /Applications/AMPPS/www/distinct.dev
/wp-content/themes/distinct/template-about.php
on line 6

However, using url: "get-to-know-us", I can see it has posted the value:-

member 71
Source member=71

So I still don’t understand why I can’t display this in PHP?

0

Leave a Comment