I have a dropdownlist when it changes the value, it must change a content from a div. A kind of filter.
What happens is the content of the div changes but it redirects to another link. Since I don’t have knowledge on AJAX I used a tutorial from w3schools (http://www.w3schools.com/php/php_ajax_database.asp)
Here is my view:
...
<script>
function showUser(str) {
if (str==="") {
document.getElementById("transactions").innerHTML="";
return;
}
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 (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("transactions").innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("GET",document.location.href="filter?by="+str,true);
xmlhttp.send();
}
</script>
<?php $this->head() ?>
</head>
...
<?=Html::dropDownList(
'test', //name
'b', //select
['' => 'Select Filter...', '1' => 'Exchanging Now', '2' => 'Last Exchanged', '3' => 'Last Offered', '4' => 'Last Discounted', '5' => 'Last Recieved', '6' => 'View All'],
['onchange'=> 'showUser(this.value)'])
?>
It is always reedirecting to localhost/.../filter?by=x showing the right info.
How can I stop this redirect? In my controller I’m returning a string. Is that a problem?