您好,我是 Angular js 和 codeigniter 的新手。
所以我在从 angularjs 服务发送对象到 codeigniter Controller 时遇到了问题。
这是我的代码。
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'));
}
并且我收到错误“不允许的关键字符。$$hashKey” 那么我的代码有错吗?或者有更好的方法来解决这个问题吗?
已解决========================================
因此,如果您遇到像我一样的问题,请转到您的文件夹 系统/核心/input.php
找到函数_clean_input_keys($str),函数 block 应该是这样的:
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;
}
这样你就可以看到包含正则表达式的preg_match。 您可以将异常添加到该正则表达式中。 或者,如果您不知道该怎么做,只需阻止该代码并仅返回 $str。
最佳答案
我知道这已经过时了,但是要删除帖子中的 $$hashKey,请使用 angular.copy() 删除它。所以:
data: $.param({
"product" : angular.copy(products)
})
关于javascript - 如何将数组从 Controller angularjs 发送到 codeigniter Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21260800/