如何将数组从控制器angularjs发送到codeigniter控制器?

时间:2021-01-26 13:42:26

Hello I'm new in angular js and codeigniter.

你好,我是角js和codeigniter的新成员。

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

因此,我在将对象从angularjs服务发送到codeigniter控制器时遇到了问题。

there are my code.

有我的代码。

angular (service.js) :

角(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) :

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?

我得到一个错误"不允许键字符。$$ $hashKey“那么我的代码是错误的吗?或者有更好的方法来解决这个问题吗?

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

解决了= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

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

如果你有和我一样的问题,去你的文件夹系统/core/input.php

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

找到函数_clean_input_keys($str),函数块应该是这样的:

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.

可以看到preg_match,它包含正则表达式。可以将异常添加到正则表达式中。或者,如果你不知道该怎么做,那就阻塞代码,只返回$str。

1 个解决方案

#1


3  

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

我知道这是旧的,但是要在你的文章中删除$$hashKey,使用angular.copy()删除它。所以:

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

#1


3  

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

我知道这是旧的,但是要在你的文章中删除$$hashKey,使用angular.copy()删除它。所以:

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