My website has a search filter form embed using AJAX. When I access page with simple type parameter it return the content but when I am trying to pass other parameters using GET then it shows 404. Example: http://www.website.com/?type=871 (it shows default content) http://www.website.com/?type=871&controller=abc (it return 404)
Jquery Ajax Code
$.ajax({
type: 'GET',
url: $(this).attr('action') + '?type=871',
data: $(this).serialize(),
success: function (data) {
$('#searchresults').html(data);
}
});
Typoscript code
mlAjax = PAGE
mlAjax {
typeNum = 871
}
[globalVar = GP:type = 871]
config {
disableAllHeaderCode = 1
xhtml_cleaning = 0
admPanel = 0
debug = 0
no_cache = 1
}
tt_content.list.10 >
// Insert content that can handle the request
mlAjax {
10 = COA
10 {
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
}
}
}
[global]
Form tag
<f:form id="searchform" action="searchResult" method="get" noCacheHash="TRUE">
A working method that i constantly use in TYPO3 v9 and v10:
YourHtml.html
<f:form action="searchform"
class="form class_ajax"
object="{search}"
pageUid="{settings.flexform.pages.list.pid}"
name="search"
noCache="true"
method="post"
pageType="871"
>
Here is very important that you include the pageType
as well.
Setup.typoScript
ajaxSearch_page = PAGE
ajaxSearch_page {
typeNum = 871
10 = USER
10.userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
10.extensionName= ExtensionName
10.pluginName = PluginName
10.vendorName = Vendor
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:application/json
xhtml_cleaning = 0
debug = 0
no_cache = 1
admPanel = 0
}
}
You do not need the [globalVar = GP:type = 871]
since you already have defined that on the pageType 871 you are going to use another PAGE configuration.
Please make sure you have your TypoScript exactly how i wrote it
YourJs.js
var resultContainer = $('#yourContainer');
var service = {
ajaxCall: function (url) {
$.ajax({
url: url,
cache: false,
data: {url: url},
method: 'POST',
success: function (result) {
resultContainer.html(result).fadeIn('fast');
},
error: function (jqXHR, textStatus, errorThrow) {
resultContainer.html('Ajax request - ' + textStatus + ': ' + errorThrow).fadeIn('fast');
}
});
}
};
$(document).on('click', '#searchform', function (ev) {
var url=$(this).attr('action');
ev.preventDefault();
service.ajaxCall(url);
});
config/sites/yourSite/config.yaml
routeEnhancers:
PageTypeSuffix:
type: PageType
map:
form.json: 871