You shouldn’t need to make direct calls to your theme files – use the AJAX API, and make all requests to admin-ajax.php
(that way, WordPress’ll be loaded for you, and you won’t need to assume the file hierarchy in order to load it manually).
$.get(
'<?php echo admin_url( 'admin-ajax.php' ) ?>',
{
"color_theme" : "test",
"color_spot" : "1",
"action" : "change_color"
},
function( data ) {
doColor( '#theme_header_color', data );
}
);
And in functions.php
;
function __do_color_ajax()
{
$theme = $_GET['color_theme'];
$spot = $_GET['color_spot'];
// do something
die( 'AJAX output' );
}
add_action( 'wp_ajax_nopriv_change_color', '__do_color_ajax' );
See how the suffix of the hook, wp_ajax_nopriv_change_color
, matches the action variable in the AJAX request? See this SE answer for more info.
Note I’ve also prefixed the other AJAX request variables, as you should namespace custom $_GET
and $_POST
variables in the same way you do PHP variables and functions.
Also check out the codex on the AJAX API.