사람들은이 코드를 jquery로 변환해야한다고 추천하고 있습니다.하지만 도구와 방법은 어디에서 어떻게, 어떻게 할 수 있으며 XMLHttpRequest가 jQuery와 어울리지 않는 이유는 무엇입니까 ??어떻게 일반 자바 스크립트 코드를 jQuery로 변환 할 수 있습니까?
는이 코드를 가지고 :
function showVal(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "* Please type in School Name.";
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) {
if (xmlhttp.status == 200) { // break this into 2 statements so you can handle HTTP errors
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
} else {
document.getElementById("txtHint").innerHTML = "AJAX Error (HTTP "+xmlhttp.status+")";
}
}
}; // functions declared in this way should be followed by a semi colon, since the function declaration is actually a statement.
// encodeURIComponent() does all the escaping work for you - it is roughly analogous to PHP's urlencode()
// xmlhttp.open("GET","ajaxFuncs2.php?q="+encodeURIComponent(str),true);
xmlhttp.open("GET","ajaxFuncs2.php?q="+encodeURIComponent(str),true);
xmlhttp.send();
}
. 공식 웹 사이트 http://docs.jquery.com/How_jQuery_Works로 시작하십시오. –
작동하는 경우 전환 할 이유가 없습니다. 실제로 jQuery를 사용하지 않고로드하는 경우 jQuery로 변환하면 페이지 크기가 증가합니다. –
다른 jquery 코드로는 작동하지 않습니다. S – Drazek