I have a very simple script like so:
$(function() {
var url = theme_directory + '/func/api.php';
$.get( url, function(data) {
alert("Data Loaded: " + data);
});
});
And the api.php looks like this:
<?php
echo('hello');
define('WP_USE_THEMES', false);
require_once( dirname( __FILE__ ) . '/../../../../wp-blog-header.php' );
This works. However when I put the exit below like so:
<?php
define('WP_USE_THEMES', false);
require_once( dirname( __FILE__ ) . '/../../../../wp-blog-header.php' );
echo('hello');
And I browse to the api.php it shows me 'hello' however when I use the javascript it doesn't show me the alert. Moving the hello back up, it works again. It gets me so confusedddd.
<?php
echo ' ';
define('WP_USE_THEMES', false);
require_once( dirname( __FILE__ ) . '/../../../../wp-blog-header.php' );
print_r($wp);
Now javascript will show me the contents of $wp... however, removing the echo ' ';
and the javascript alert will not be triggered.
It has something to do with the WordPress Permalinks. When I turn it off, it works, when I turn it on it does not.
the problem maybe is in require_once( dirname( __FILE__ ) . '/../../../../wp-blog-header.php'
); , that path is not found
however if you simply want to see the resulting string use load().
$('#input').load('api.php');
I believe that WordPress's "fancy" permalinks use Apache's mod_rewrite
. If Apache is returning an HTTP 301 to redirect the browser, jQuery won't follow that redirect. You might want to check out this Stack Overflow question to get around that.