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.

7
  • 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. Commented Jan 21, 2014 at 14:46
  • Are there any key post data that has a dot in it? Commented Jan 21, 2014 at 14:51
  • no it's just like this {"product":[{"id":"1","product_name":"apple","price":"11","discount_price":"1"}]} Commented Jan 21, 2014 at 14:56
  • stackoverflow.com/questions/11442632/…. Also check this file system/libraries/Input.php in codeignitor Commented Jan 21, 2014 at 15:20
  • Hello, It's still not working, but I'll do some research again. Thank you for the reference anyway. Commented Jan 22, 2014 at 2:34

1 Answer 1

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) 
        })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.