Request Ajax Codeigniter

Asked

Viewed 342 times

1

I am receiving the following error when sending json data via ajax using codeigniter: Disallowed Key Characters. When sending only one object works smoothly, but when sending more of an object returns the error to me.

jQuery.post( "http://localhost/endereco", 
                    {informacao1:"dado1", informacao2:"dado2"},
                    function(data){     

                            alert(data);

                    }   
        );

1 answer

1


What you can do is create a file MY_Input.php within application/core

<?php

class MY_Input extends CI_Input {

    /**
     * Clean Keys
     *
     * This is a helper function. To prevent malicious users
     * from trying to exploit keys we make sure that keys are
     * only named with alpha-numeric text and a few other items.
     * 
     * Extended to allow: 
     *      - '.' (dot), 
     *      - '[' (open bracket),
     *      - ']' (close bracket)
     * 
     * @access  private
     * @param   string
     * @return  string
     */
    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;
    }

}
  • But this method no longer exists within the system/core/input.php file?

  • Even so I created and it didn’t work.

  • Yes, but there is a small change. I was having this same problem and what solved me was this. Try to take a look at this link. https://ellislab.com/forums/viewthread/140333/#854563

  • The link helped me. I didn’t even have to create the file. I just changed the _clean_input_keys method of the system/core/input.php file the way you wrote it. Thank you.

  • But it is not advised to change anything from system and create the file in your directory application/[core|libraries] and with that, if one day, a new version comes out, you will only need to change the system folder without major problems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.