Ïà¹ØµÄajax²Ù×÷JSÎļþ
document.getElementById("search").onclick = function() { var request = new XMLHttpRequest(); request.open("GET", "server.php?number=" + document.getElementById("keyword").value); request.send(); request.onreadystatechange = function() { if (request.readyState===4) { if (request.status===200) { document.getElementById("searchResult").innerHTML = request.responseText; } else { alert("·¢Éú´íÎó£º" + request.status); } } } } document.getElementById("save").onclick = function() { var request = new XMLHttpRequest(); request.open("POST", "server.php"); //´Ë´¦Òª°Ñ¸÷¸öÊäÈë¿ò»ñÈ¡µ½µÄ¸÷¸öÔ±¹¤ÐÅÏ¢Ò»URLµÄ·½Ê½À¦°óµ½dataÖÐ var data = "name=" + document.getElementById("staffName").value + "&number=" + document.getElementById("staffNumber").value + "&sex=" + document.getElementById("staffSex").value + "&job=" + document.getElementById("staffJob").value; request.setRequestHeader("Content-type","application/x-www-form-urlencoded"); request.send(data); request.onreadystatechange = function() { if (request.readyState===4) { if (request.status===200) { document.getElementById("createResult").innerHTML = request.responseText; //ʵʱ¸üÐÂÊäÈë¿òÊäÈëÄÚÈݺóµÃµ½µÄ½á¹û } else { alert("·¢Éú´íÎó£º" + request.status); } } } }ÐèÒªÌرð×¢Ò⣬²»ÒªÍü¼ÇÉèÖÃcontent-type
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
²Ù×÷½á¹ûʾÒâͼ
±¾ÎÄÓɱ¾ÈË×ܽá×ÔĽ¿ÎÍø@WayneJµÄajaxÈ«½Ó´¥¿Î³ÌÁ´½ÓÃèÊö£¬´úÂëÓë½Øͼ·ÇÔ´´£¬½ö¹©Ñ§Ï°£¬ÈçÓÐÇÖȨÇë˽ПæÖª¡£
42 ÈËÍƼö
ÆÀÂÛ
ÊÕ²Ø
ÆÀÂÛ£¨Enter+Ctrl£©
ÈÈÃÅÆÀÂÛ
ÆÀÂÛ¼ÓÔØÖÐ...
ÌõÆÀÂÛ
ÆÀÂÛ¼ÓÔØÖÐ...
¡¡