0

我已经通过 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()
4

2 回答 2

0

在Javascript中将所有复选框值作为数组传递

这处理您选择值并将它们传递给“tper”的问题

于 2013-03-06T00:16:13.447 回答
0

复选框是否像数组一样定义?例如:

 <input type="checkbox" name="selected[]">
于 2013-03-05T23:55:18.723 回答