I finally made my AJAX working in Extbase Typo3 6. However, I'm trying to use the returned array from AJAX in my FLUID view.
my Ajax action in Controller:
public function ajaxAction(){
$id = $this->request->getArgument['id'];
$record = $this->articleRepository->findByUid($id);
return json_encode(['record'=>$record,'status' => 'Loaded']);
}
My AJAX :
function dropCall(selectFieldObj) {
$.ajax({
type: 'POST',
url: link,
dataType: 'json',
success: function(data){
alert(data.status);
}
});
}
Now the question is how do I use the data object
sent from the controller action in my View ? The alert is being displayed.
My List.html
view
<script type="text/javascript">
var link
= '<f:uri.action action="ajax" controller="Article" pageType="99" arguments="{data:1}"/>';
</script>
<script type="text/javascript" src="fileadmin/myScript.js"></script>
<select id="drop" onchange="dropCall(this)">
<option value="1">Apple</option>
<option value="2">Mango</option>
<option value="3">Grape</option>
</select>
In my view, I should be able to do something like
<h1> {record.name} </h1>
EDIT
The object record
might contain many properties and each record.property
like record.name
will be under <h1>
tags and record.somethingelse
can be under some under tag.
Just like we send objects
from controller
to view
and use them in FLUID, I would want to do the same with AJAX