Whats the best way to convert this code to jquery? I tried it this way but noticed that internet explorer gives me trouble with this. So I decided to do it with jQuery but I see a lot of methods but I dont know how to make the same function with it.
function updateField(str, id, prevvalue, value, vehicletype) {
if (str == "") {
document.getElementById(id).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(id).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "inc/form_rest.php?q=" + str + "&prevvalue=" + prevvalue + "&value=" + value + "&vehicletype=" + vehicletype, true);
xmlhttp.send();
}
The simplest would be to use get :
Note that I let jQuery build the url, which will also ensure that the urlencoding is properly done.
As you’re only using the response to fill an element, you could also have used