简体   繁体   中英

How can I send array from controller angularjs to codeigniter controller?

Hello I'm new in angular js and codeigniter.

So I got problem with sending object from angularjs services, to codeigniter controller.

there are my code.

angular (service.js) :

help.updateProductService = function(products){
        return help.http({
            url: "/www/Rubee/index.php/pages/editProduct/",
            method: "POST",
            data: $.param({
                "product" : products 
            }),
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        })
    }

codeigniter (pages.php) :

public function editProduct(){
        print_r($_POST);
        print_r($this->input->post('product'));
    }

and I got an error "Disallowed key character. $$hashKey" so am I wrong with the code? or any better way to solve this?

SOLVED ======================================

So if you have same problem like me, go to your folder system/core/input.php

and find function _clean_input_keys($str), the function block should be like this :

function _clean_input_keys($str)
{
    if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
    {
        exit('Disallowed Key Characters.');
    }

    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
        $str = $this->uni->clean_string($str);
    }

    return $str;
}

so you can see preg_match , that contain regular expression. you can add your exception to that regular expression. or if you don't know what to do just block that code and return $str only.

I know this is old but to get rid of the $$hashKey in your post, use angular.copy() to remove it. So:

data: $.param({
            "product" : angular.copy(products) 
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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