Ajax数据不适用于会话

时间:2017-10-04 09:22:16

标签: javascript php ajax codeigniter

我想通过ajax和控制器存储中的下拉值向下发送下拉和复选框值,并将其与复选框值一起使用,但这不起作用。我希望在选择下拉菜单时显示其值,但是选中复选框,然后显示下拉和复选框的值。

这是我的下拉菜单和复选框

  function showUser1(strr) {
     if (strr == "")   
     {
       document.getElementById("txtHint").innerHTML = "";
        return;
     } 
     else 
     { 
        if (window.XMLHttpRequest) {
          // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp = new XMLHttpRequest();
        }else  {
         // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
       xmlhttp.onreadystatechange = function() {
       if (this.readyState == 4 && this.status == 200) {
          document.getElementById("txtHint").innerHTML = this.responseText;
       }
     };
      xmlhttp.open("GET","Search/sorted_deals?strr="+strr,true);
      xmlhttp.send();
    }
   }
 function showUser() {
 var str = []
 var checkboxes = document.querySelectorAll('input[type=checkbox]:checked')
 for (var i = 0; i < checkboxes.length; i++) 
 {
     str.push(checkboxes[i].value)
 }
 if (window.XMLHttpRequest) {
 // code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp = new XMLHttpRequest();
  }
   else  { // code for IE6, IE5
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
   xmlhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) 
    {
         document.getElementById("txtHint").innerHTML = this.responseText;
     }
  };
   xmlhttp.open("GET","Search/sorted_deals?str="+JSON.stringify(str),true);
   xmlhttp.send();
}

这是我正在使用的ajax

$_SESSION['variable']=$this->input->get('strr');
$variable=$_SESSION['variable'];
if($variable=="byname")
{   
   echo $_SESSION['variable'];
    //$user_search=$this->Deals->sort_by_name($deal_name,$city_id,$city_status);
} 
$variables = json_decode($this->input->get("str"));
for ($a = 0; $a < count ($variables); $a++) 
{
    if($variables[$a]=="featured")
     {
         echo $variables[$a];  
         echo $_SESSION['variable'];
     } 
}

这是我在控制器中的功能

results[i].get("user_id").id

1 个答案:

答案 0 :(得分:0)

XMLHttpRequest请求不允许在此处显示Cookie标头原因:Why cookies and set-cookie headers can't be set while making xmlhttprequest using setRequestHeader?,因此请尝试使用其他方式来实现此XHR请求。