If you want to use Ajax with TYPO3 (in my case I was using jQuery)  then you may want to use the eID mechanism. eID stands for Extension ID. When Typo3 receives a URL that contains the eID parameter (for example: www.mydomain.com/index.php?eID=myextension), then the normal process stops and there won’t be any frontend output, it’s not cached and doesn’t generate header code etc. With this the entire FE of TYPO3 is omitted. The only output is the result of our method. Before using this, every time I tried to use ajax with jQuery and print the results, I was receiving the entire HTML structure of the page with all the header and all the information from the frontend. This is what you need to do:

1 – Create a new php class inside your custom extension

require_once(PATH_t3lib . 'class.t3lib_befunc.php');
require_once(PATH_t3lib . 'stddb/tables.php');
require_once(t3lib_extMgm::extPath('cms', 'ext_tables.php'));

class tx_whatisit_eID {
public function init() {
public function main() {
// get params for query
$param = t3lib_div::_GET();
$name = $param['name'];
echo "hello world" . $name;

if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/myextension/class.tx_whatisit_eid.php'])) {
$module = t3lib_div::makeInstance('tx_whatisit_eID');

2- Register the class in ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['myextension'] = 'EXT:myextension/class.tx_whatisit_eid.php';

3- In your javascript file you can call:

$.get("http://mydomain.com/index.php?eID=myextension", {name: 'John'}, function(data) { alert(data); } );

Hope you find this useful. Thanks to Niels Frohling for his help too.