Hallo!
Ich versuche in eine eigene Extension einen einfachen Ajax-Aufruf einzubauen, aber ich bekomme einfach nichts zurück, bzw. einen Fehler in der Ajax-Funktion (SyntaxError: Unexpected end of JSON input).
JS:
[code]function fetchdata(){
var zeit;
$.ajax({
url: 'index.php?type=6666&tx_abfahrtsmonitor_feabfahrtsmonitor[controller]=Zeiten&tx_abfahrtsmonitor_feabfahrtsmonitor[action]=ajax',
method: 'POST',
dataType: "json",
async: false,
success: function(response){
console.log("Success: "+response.zeit);
zeit = response.zeit;
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + textStatus + ' ' + errorThrown);
}
});
return zeit;
}
[/code]
TS:
[code]ajax_api = PAGE
ajax_api {
typeNum = 6666
config {
disableAllHeaderCode = 1
xhtml_cleaning = 0
debug = 0
no_cache = 1
admPanel = 0
}
10 < tt_content.list.20.abfahrtsmonitor_feabfahrtsmonitor
}
[/code]
Controller:
[code]class ZeitenController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function ajaxAction()
{
$result = array();
$result["zeit"] = "17:23";
return json_encode($result);
}
}
[/code]
Ich habe schon alle Varianten ausprobiert: mit und ohne "tx_", sämtliche Plugin-Schreibweisen, beim Ajax-Aufruf den dataType geändert und weggelassen, async true und false, einfache Strings als Rückgabewert, return und echo. Es kommt entweder der Json Fehler oder nichts.
Hat vielleicht jemand eine Idee, wo ich noch debuggen könnte?
Danke und Grüße,
Stephan