All the strings on my site are pulled from a php language function named lang()
inside lang.php. The function works when I use it within the index.php file, ie:
<p><? echo lang('hello-world'); ?></p>
However, if I use elem.load('something.php');
, where something.php contains the same above code, nothing gets returned. In fact, if I type:
<p><? echo haslkdfhasdf('hello-world'); ?></p>
I don't even get an error. Now, after reading this Call PHP function in ajax and using header() I still don't get a returned string. My question then is, why doesn't the function work from inside an external php file loaded through AJAX, and what am I missing?
[EDIT] Whoops forgot my AJAX code. Here's what I'm using to load the file:
$('#main-content').load('_foo/views/error.php');
Here is the error.php file:
<p id="ajax-error-message">
<? echo lang('html'); ?>
</p>
Now, I know that the file loads because if I replace the function with "echo 'Hello World';" it displays it properly. And here is the site incase you need it: http://afoobar.com , when you click on HTML5 Sandbox it executes the AJAX.
I'll try your suggestions in the mean time!