在jqueryajax中将数组值传递给url


passing array value to url in jquery ajax

我将数组值传递给url,如下所示查看代码

from_multiselect('functio[]',$function,'','id=function')

baseurl/test/roles?id=1,2,3

这是我的jquery

$("#role > option").remove(); 
var id = $('#function').val(); 
alert(id);
var str=new Array();
alert(id);
$.ajax({
   type: "POST",
   url: "test/roles?id="+id, 
   success: function(roles) 
   { 
     alert(roles);
     $.each(roles,function(id,roles) 
     {
        var opt = $('<option />'); 
        opt.val(id);
        opt.text(roles);
        $('#role').append(opt); 
     });
   }
 });
 });
});

当我在url中传递数组值时,页面出现错误,类似于不允许的关键字符

提前感谢

然后像这样发布这个数组:

$("#role > option").remove(); 
var id = $('#function').val(); 
var valArray = id.split(',');
var str=new Array();
alert(id);
$.ajax({
type: "POST",
url: "test/roles?id="+valArray, 
success: function(roles) 
{ alert(roles);
$.each(roles,function(id,roles) 
{
var opt = $('<option />'); 
opt.val(id);
opt.text(roles);
$('#role').append(opt); 
});
}
});
});
});

在方法中添加参数以接受数组。

这是CodeIgniter错误。

所以,要解决这个问题,请转到

/application/config/config.php

搜索

$config['permitted_uri_chars']

更改为:

$config['permitted_uri_chars'] = 'a-z 0-9~%'.':_'+-,?&=';