我的网站有一个使用AJAX的搜索过滤器表单嵌入。当我访问简单的页面时 类型 但当我试图使用GET传递其他参数时,它显示404。例如http:/www.website.com?type=871 (它显示默认内容)http:/www.website.com?type=871&controller=abc。 (它返回404)
Jquery Ajax代码
$.ajax({
type: 'GET',
url: $(this).attr('action') + '?type=871',
data: $(this).serialize(),
success: function (data) {
$('#searchresults').html(data);
}
});
打字稿代码
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]
表格标签
<f:form id="searchform" action="searchResult" method="get" noCacheHash="TRUE">
我在TYPO3 v9和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"
>
这里非常重要的是,你要包括 pageType
也是。
Setup.typoScript
ajaxSearch_page = PAGE
ajaxSearch_page {
typeNum = 7356445
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
}
}
你不需要 [globalVar = GP:type = 871]
因为你已经在 pageType 871 你要用另一个 PAGE 配置。
请确保你的TypoScript和我写的一模一样。
你的Js.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);
});
configsitesyourSiteconfig.yaml)。
routeEnhancers:
PageTypeSuffix:
type: PageType
map:
form.json: 871