Im making a module where I have 2 dropdownlists.In the first List there are Car brands (like BMW,Audi,Seat etc). When The user select a Brand the Second List should get filled with the different Models of that Brand ( Seat ibiza,Seat Leon if you choose Seat ) . So i need to add some ajax. I never used ajax before , so after some reading the last days i made this :
<script>
function showUser(str) {
var xmlhttp;
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("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","query.php?q="+str,true);
xmlhttp.send();
}
</script>
query.php is a file located in the tmpl folder (where the default-view file is located). This would normally work if i didnt use Joomla , but as i found out there are different ways on adding Ajax on Joomla.The most guys suggested to create a component and add it through view file.Also as i saw everyone use jquery ajax.Im forced to use that ? I tried to study a bit that technique but i got lost. Could someone explain what should be the easiest way to add Ajax in the module?(I didnt understood very clear that component-view file way) And if it is compulsory for Jquery Ajax help me prepare the call ?
I made something like this, dunno if im completly out of the way:
<script>
$(document).ready(function() {
$('#cats').change(function() {
var myReq = new Request({
method: 'get',
url: 'modules/mod_dtm_cart/tmpl/query.php'
//More code here
});
});
});
</script>
Whole code: http://pastebin.com/dAGQHJun Atm it doesnt call the query.php file and the 2nd list is filled with exactly the same elements as list1.