如何將以下代碼轉換爲僅使用jQuery庫?將AJAX轉換爲jQuery
<html>
<head>
<script>
function do_it(value)
{
function newXMLHttpRequest()
{
try{ return new XMLHttpRequest(); }catch(e){}
try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){}
try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
return null;
}
var ajax_request = false;
ajax_request = newXMLHttpRequest();
var url = "test.pl?b64="+value;
ajax_request.open("GET",url,1);
ajax_request.onreadystatechange = function()
{
if(ajax_request.readyState == 4)
{
var response = ajax_request.responseText;
document.getElementById("in").innerHTML = response;
}
}
ajax_request.send(null);
}
</script>
</head>
<body>
<form>
<input type="text" name="string" onkeyup="do_it(this.value)"/>
<input type="submit" name="submit">
</form>
<div style="position:absolute;width:200px;height:200px; background-color:yellow; margin-top:100px;" id="in"></div>
</body>
</html>
對不起,我也許應該提到,我實際上沒有使用jQuery任何實踐經驗,我在過程中與現在熟悉自己...
謝謝,作品像一個魅力。不能相信一行代替了所有的代碼......另外你會如何去執行jquery中的onkeyup事件? – 2010-11-22 13:50:58
請看看我的編輯,我希望這可以幫助你。 – oezi 2010-11-22 13:58:50