简体   繁体   English

从视图传递jquery var到codeigniter中的控制器

[英]passing jquery var from view to controller in codeigniter

This is in script .ready() function which fetch existing files from database and putting in jquery var splitfiles . 这在脚本.ready()函数中,该函数从数据库中获取现有文件并放入jQuery var splitfiles which is in array formate. 在数组甲酸盐中。

  var splitfiles = '<?php echo @$projectDetails->upload_file; ?>'; 

this line gives array of attached file from view in controller 该行从控制器视图中提供附加文件的数组

 $arrayoffiles = json_encode($joinfiles);

I want to get this splitfiles var in controller and then merge with $arrayoffiles after that store in database with other form data. 我想在控制器中获取此splitfiles var,然后在将$arrayoffiles与其他表单数据存储在数据库中之后合并。

I tried with this solution to pass 'splitfiles' to controller by this bellow code but i am not getting in the controller 我尝试使用此解决方案通过以下代码将``splitfiles''传递给控制器​​,但我没有进入控制器

 $(document).ready(function() {
    $.ajax({
    url: '<?php echo site_url("trusts/fundsRaisingModule"); ?>',                       
    type: 'GET',  
    dataType: 'json',   

    data: {
        splitfiles:splitfiles,
        // key : value pair. You can send as many pair as you want like this
    }

   });
 });

In controller i am not getting the 'splitfiles' 在控制器中,我没有得到'splitfiles'

    $files=$_REQUEST['splitfiles'];

giving error :undefined index 'splitfiles' so help me to pass jquery variable from view to controller in codeigniter after that i will try to merge the two arrays Thanks in advance. 给错误:未定义的索引“ splitfiles”,所以帮助我在视图之后将jquery变量从视图传递到控制器中的codeigniter中,我将尝试合并两个数组。

To achieve this use jquery ajax() and send the js variable to controller method and use it as you want. 要实现此目的,请使用jquery ajax()并将js变量发送到控制器方法,然后根据需要使用它。

Its syntax is: 其语法为:

$(document).ready(function(){
    $.ajax({
        url: 'controller_method',                        
        type: 'POST',                                  
        data: {
            splitfiles  :splitfiles,
            // key : value pair. You can send as many pair as you want like this
        },
        success: function(response){    // response from process
            // do your stuff here
        }
    });
});

controller_method controller_method

$splitfiles = $_REQUEST['splitfiles'];
// do your stuff here

Note: Don't forget to add the jquery library in your code. 注意:不要忘记在代码中添加jquery库。

首先将该jQuery变量发送到视图的任何隐藏输入中,然后通过GET或POST方法将该输入值获取到控制器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM