简体   繁体   English

我正在尝试通过ajax将参数传递给数据

[英]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.

相关问题 我正在努力通过Ajax将数据传递给控制器 - I am struggling to pass data to controller through Ajax 我正在尝试使用 ajax 通过 laravel 中的模态上传图像 - I am trying to upload image through modal in laravel using ajax 我正在尝试通过将参数传递给访存调用来显示特定数据 - I am trying to display specific data by passing a parameter to a fetch call 我无法通过AJAX将会话存储数据发送到服务器 - I am not able to send session storage data through AJAX to the server 我正在尝试使用来自 html 中的 api 的数据传递参数 - I'm trying to pass a parameter with data that comes from an api in the html 作为$ ajax参数MVC传递数组 - Pass through an array as a $ajax parameter MVC 为什么我无法通过 ajax 将数据 URL 传递给 wordpress 函数 - Why i cannot pass data URL through ajax to wordpress function 尝试将 function 作为参数传递时,我缺少什么额外的步骤? - What extra step am I missing when trying to pass a function as a parameter? 我正在尝试将模式按钮传递给 laravel 中的 ajax 搜索结果表 - I am trying to pass modal button to ajax search result table in laravel 当我尝试将值作为通过Ajax传递到php文件时,代码中的错误是什么? - What is the error in my code when i trying to pass values as Get through Ajax to a php file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM