2

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.

singgih
  • 66
  • 6
  • ehmm... still not working. If I try data, and debug my javascript with chrome. in network tab i can see my data send by the angular. but I don't understand why it's always null when I try access it from codeigniter. – singgih Jan 21 '14 at 14:46
  • Are there any key post data that has a dot in it? – Nouphal.M Jan 21 '14 at 14:51
  • no it's just like this {"product":[{"id":"1","product_name":"apple","price":"11","discount_price":"1"}]} – singgih Jan 21 '14 at 14:56
  • http://stackoverflow.com/questions/11442632/how-can-i-make-angular-js-post-data-as-form-data-instead-of-a-request-payload. Also check this file `system/libraries/Input.php` in codeignitor – Nouphal.M Jan 21 '14 at 15:20
  • Hello, It's still not working, but I'll do some research again. Thank you for the reference anyway. – singgih Jan 22 '14 at 02:34
  • Hello @Nouphal.M it's working. thank you so much. I edited the Input.php in codeigniter and it's work well. anyway it's not system/libraries it's system/core. thank to you once again. – singgih Jan 22 '14 at 07:51
  • Please answer this question how you did it so that others can benifit with the same problem – Nouphal.M Jan 22 '14 at 08:03

1 Answers1

3

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) 
        })