Hallo,

kann mir jemand ein Beispiel geben wie ich ajax calls in Typo3 einbinde (fluid / exbase) was ich im netz gefunden habe funktionierte leider nich richtig ... oder habe ich etwas vergessen...

im template
<script type="text/javascript"> var actionsPathFromViewHelperSetInTheView = '<f:uri.action action="ajax" controller="Fahrzeuge" pageType="1249012345" />'; </script> <f:form.select name="ANZEIGE_MARKE_ID" options="{search.ANZEIGE_MARKE_ID}" id="tx-srwebmobile24cm-ANZEIGE_MARKE_ID" optionValueField="id" optionLabelField="bezeichnung" additionalAttributes="{onChange : 'performAjaxCall(this,\'ANZEIGE_MODELL\');'}" > <select class="search_single_select" id="tx-srwebmobile24cm-ANZEIGE_MARKE_ID"><option>dummy</option></select>
                </f:form.select>

 js

function performAjaxCall(selectFieldObj,key) {
    alert(selectFieldObj + ' --- ' + key);
    $.ajax({
        url: actionsPathFromViewHelperSetInTheView,
        data:{
"tx_srwebmobile24cm_webmobile24[key]":selectFieldObj.value
        },
        success:function (data) {
            // do something with your json
            alert('Load was performed.');
            alert(data);
        }
    });
}

controller

  public function ajaxAction() {
print_r('ajax start');
    // try to always validate the incoming arguments
if (!$this->request->hasArgument('uid') || intval($this->request->getArgument('uid')) == 0) {
        header('HTTP/1.1 400 Bad Request');
        return json_encode(array('error'=> 'Bad request'));
    }

    $uid = intval($this->request->getArgument('uid'));

    $dataFromRepo = 'test ausgabe ';
    if ($dataFromRepo == null) {
        header('HTTP/1.1 404 Not found');
        return json_encode(
array('error'=> 'Not found or you have no access or something else... happens...')
        );
    }
    $resultArray = array(
        "field1" => $dataFromRepo,
        // etc...
    );

    return json_encode($resultArray);
}

typoscript setup.txt

ajax = PAGE
ajax {
# You don't need to change this typeNum
typeNum = 1249012345
config {
disableAllHeaderCode = 1
disablePrefixComment = 1
additionalHeaders = Content-type: text/plain
xhtml_cleaning = 0
no_cache = 1
admPanel = 0
debug = 0
}
}

|ausgabe in der konsole: |||Page Not Found | Reason: Request parameters could not be validated (&amp;cHash comparison failed||)|habe ich noch etwas vergessen?

ömm ja was habe ich vergessen oder falsch gemacht?

--
Christian

_______________________________________________
TYPO3-german mailing list
TYPO3-german@lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german

Antwort per Email an