我已经通过 ajax 编写代码以通过 ajax 发送名称和角色,名称发送成功,但选择超过 2 个角色时复选框不发送。
ajax代码
var HttPRequest = false;
function doCallAjax(Mode,Page,ID) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxRolesPermRecord.php';
var pmeters = "troles_Name=" + encodeURI( document.getElementById("roles_Name").value) +
"&tper=" + encodeURI( document.getElementById("per").value) +
'&myPage='+Page +
"&tID=" + ID +
"&tMode=" + Mode;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "load ...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
我在这样的其他页面上得到它
foreach($selected as $key=>$val)
{
$SqlInsertIntotable = mysql_query("INSERT INTO permissions_roles (id,permission_id,role_id)
value ('','".$val."','".$RoleID."')");
}
问题是
Invalid argument supplied for foreach()