このコードをjqueryに変換する必要がありますが、どのようにツールや方法がありますか、XMLHttpRequestがjQueryでうまくいかない理由は何ですか?通常のjavascriptコードを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();
}
。公式のWebサイトhttp://docs.jquery.com/How_jQuery_Worksから始めてください。 –
これが機能する場合は、切り替える必要はありません。実際、jQueryを使用していない(そしてロードしている)場合は、jQueryに変換するだけでページのサイズが増えます。 –
私の他のjqueryコードでは機能しません: – Drazek