Sha*_*han 1 ajax typo3 http-status-code-404
我的网站有一个使用 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);
}
});
Run Code Online (Sandbox Code Playgroud)
打字稿代码
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]
Run Code Online (Sandbox Code Playgroud)
表单标签
<f:form id="searchform" action="searchResult" method="get" noCacheHash="TRUE">
Run Code Online (Sandbox Code Playgroud)
我在 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"
>
Run Code Online (Sandbox Code Playgroud)
在此非常重要的是,您也应包括pageType在内。
安装程序.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
}
}
Run Code Online (Sandbox Code Playgroud)
您不需要,因为您已经在pageType 871[globalVar = GP:type = 871]上定义了您将使用另一个PAGE配置。
请确保您的 TypoScript 与我编写的完全一致
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);
});
Run Code Online (Sandbox Code Playgroud)
config/sites/yourSite/config.yaml
routeEnhancers:
PageTypeSuffix:
type: PageType
map:
form.json: 871
Run Code Online (Sandbox Code Playgroud)