[英]i am trying to pass parameter to data through ajax
I am trying to pass value through an ajax json array but value of catergory variable is not getting in controller action我正在尝试通过 ajax json 数组传递值,但 Category 变量的值没有进入控制器操作
var category = $('#category').val();
var url = $('#ajax_action_search').val();
$.ajax({
type: "POST",
data: {
'category': category
},
dataType: "json",
cache: false,
contentType: false,
processData: false,
success: function(response) {}
});
You need to use the parameter namespace matching your extension/plugin:您需要使用与您的扩展/插件匹配的参数命名空间:
$.ajax({
// ...
data: {
'tx_myext_foo[category]': category,
},
// ...
});
But you'll also need to configure the cHash
evaluation since this will lead to a HTTP request like /?tx_myext_foo[category]=X
which will fail without a matching cHash
.但是您还需要配置
cHash
评估,因为这将导致像/?tx_myext_foo[category]=X
这样的 HTTP 请求,如果没有匹配的cHash
就会失败。
This can be done with the excludedParameters
configuration option .这可以通过
excludedParameters
配置选项来完成。
Please check the Controller action if category
(parameter name) passed from the ajax is exactly same in the controller action too如果从ajax传递的
category
(参数名称)在控制器动作中也完全相同,请检查控制器动作
var category = $('#category').val();
var url = $('#ajax_action_search').val();
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
cache: false,
async: false,
url: url,
data: JSON.stringify {
category: category
},
dataType: 'json',
success: function(response) {}
});
You need to make ajaxurl with action and controller.您需要使用动作和控制器制作 ajaxurl。 and then pass the data in full format.
然后以完整格式传递数据。
var ajaxUrl = '<f:uri.action action="youraction" controller="Yourcontroller" />';
var category = $('#category').val();
$.ajax({
type: 'POST',
url: ajaxUrl,
data: '&tx_yourext_yourplugin[category]='+category,
success: function(response) {
},
});
Just make the following changes :只需进行以下更改:
var category = $('#category').val();
var url = $('#ajax_action_search').val();
$.ajax({
type: "POST",
url:url,
data: {'category': category},
dataType: "json",
success: function(response) {}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.