0

I want to send drop down and checkbox value through ajax and in controller store drop down value in session and use it with checkbox value but that is not working.i want that when drop down is selected so it show its value but when checkbox is checked then value of both drop down and checkbox will be show.

This is my drop down and checkbox

<select  class="product-sort-select" onchange ="showUser1(this.value)">
        <option value="" selected="selected">Sort By</option>
        <option value="byname"> name</option>
        <option value="bydate"> date</option>
        <option value="bypopularity"> popularity</option>
</select>




 <li class="checkbox">
    <label>
       <input type="checkbox" class="cb" id="featured" name="chk[]"  onchange="cbChange(this); showUser()" value="featured">Featured <small><?= "(".$featuredeals_count.")";?></small>
    </label>
 </li>

this is ajax i am using

  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();
}

and this is my function in controller

$_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'];
     } 
}
Ahmed Sunny
  • 2,160
  • 1
  • 21
  • 27

1 Answers1

0

XMLHttpRequest request doesn't allow cookie header reasons are shown here: Why cookies and set-cookie headers can't be set while making xmlhttprequest using setRequestHeader?, So try alternate way to achieve this XHR request.

TheTom
  • 298
  • 3
  • 15