My site has several ajax functions essentially identical (except different variable names, etc.) to the following:
function ajaxFunction(string) {
var ajaxRequest;
try {
ajaxRequest = new XMLHttpRequest();
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser broke!");
return false;
}
}
}//Anonymous function starts here
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById('div');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
} //and ends here
var QueryAjax = "?string=" + string;
ajaxRequest.open("GET", "AJAX_File.php" + QueryAjax, true);
ajaxRequest.send(null);
}
For the indicated anonymous function, the javascript lint found at http://www.javascriptlint.com/online_lint.php warns me I should add a semicolon at the end of this function (before the comment //and ends here in the code above) and that the function does not always return a value; the stricter lint found here: http://www.jslint.com/ warns me ajaxRequest.readyState == 4 should instead be ajaxRequest.readyState === 4.
Does anyone know how detrimental (if at all) the lack of semicolon and lack of "=== 4" are? Also, why does the function not always return a value? My site uses about 50 ajax functions similar to the one above and seems to perform great, but perhaps making these changes will speed up the execution of the functions? Any tips/advice would be greatly appreciated!