Not quite clear where you are missing data? Which part is an empty string exactly?
Jan 10, 2023
15
Level 1
GEt only an empty string from ajax request
Hello, im trying to build an function, and i think it should work but my get request is always sending an empty string and not the rendered view. Does anybody have an ides where the mistake is.
My Function in the controller.
public function order($request)
{
$value = $request->input('value');
$section = $request->input('section');
switch ($section) {
case 'mediadata':
$categories = Category::where(Category::ATTRIBUTE_PUBLICATION_TYPE, Category::TYPE_MEDIA_DATA)
->where(Category::ATTRIBUTE_IS_ONLINE, 1)->get();
$publications = [];
foreach ($categories as $cat) {
foreach ($cat->publications as $pub) {
$publications[] = $pub;
}
}
$publications = collect($publications)->sortBy('name');
$letters = [];
$publicationLetter = [];
foreach ($publications as $publication) {
$letters[] = strtoupper($publication->name[0]);
$letters = array_unique($letters);
foreach ($letters as $letter) {
if ($letter === strtoupper($publication->name[0])) {
$publicationLetter[$letter][] = $publication;
}
}
}
$sortedArray = collect($publicationLetter)->sortKeys();
$view = view('frontend.mediaData.sortData', compact('sortedArray'));
break;
}
return $view->render();
}
My AJAX Function
function getFilteredData(type, section) {
let value
switch (type) {
case 'search':
value = $('#searchField').val()
break
case 'order':
value = $('#selectField').val()
break
}
$.ajax({
url: '{{route('filter')}}',
method: 'get',
data: {
type,
section,
value,
},
success: (res) => {
console.log(res)
$('.filter-container').html(res)
},
})
}
Please or to participate in this conversation.