課程
/前端開(kāi)發(fā)
/JavaScript
/Ajax全接觸
可以就是在瀏覽器里創(chuàng)建員工信息 并查看出來(lái)嗎 ???(不需要表單結(jié)構(gòu))
2016-12-10
源自:Ajax全接觸 3-4
正在回答
可以用其他信息包裹員工信息,然后用js獲取這些標(biāo)簽的值。但是,這樣做不好,應(yīng)為表單結(jié)構(gòu)中有一個(gè)method屬性,可以規(guī)定數(shù)據(jù)傳輸?shù)姆绞绞莗ost還是get。
可以?。∮胊jax異步,直接在js里面:??? <script type="text/javascript">??????? document.getElementById("ll").onblur = function () {??????????? var request;??????????? if (window.XMLHttpRequest) {??????????????????????????????? //如果支持ajax??????????????? request = new XMLHttpRequest();??????????? } else {??????????????? request = new ActiveXObject("Microsoft.XMLHTTP");??????????? }??????????? request.open("post", "jie", true);????????????????????????????? //向服務(wù)器發(fā)送請(qǐng)求??????????? request.setRequestHeader("content-type","application/x-www-form-urlencoded");??????????? request.send("name="+document.getElementById("ll").value+"");?????????? ???????????? request.onreadystatechange=function(){????????????? if(request.readyState==4&&request.status==200){??????????????? //請(qǐng)求成功和響應(yīng)成功???????????????? alert(request.responseText);?????????????????????????????? //得到數(shù)據(jù)????????????? }??????????? }??????? }?????? ???? </script>
jsp代碼:
??? public void doPost(HttpServletRequest request, HttpServletResponse response)?? ??? ??? ?throws ServletException, IOException {?? ??? ?request.setCharacterEncoding("utf-8");??????? response.setCharacterEncoding("utf-8");??????? PrintWriter out=response.getWriter();??????? out.print("你好");??????? out.flush();??????? out.close();?? ?}
舉報(bào)
本課程通過(guò)一個(gè)案例,講解Ajax的相關(guān)概念原理實(shí)現(xiàn)方式和應(yīng)用
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-12-10
可以用其他信息包裹員工信息,然后用js獲取這些標(biāo)簽的值。但是,這樣做不好,應(yīng)為表單結(jié)構(gòu)中有一個(gè)method屬性,可以規(guī)定數(shù)據(jù)傳輸?shù)姆绞绞莗ost還是get。
2016-12-10
可以?。∮胊jax異步,直接在js里面:
??? <script type="text/javascript">
??????? document.getElementById("ll").onblur = function () {
??????????? var request;
??????????? if (window.XMLHttpRequest) {??????????????????????????????? //如果支持ajax
??????????????? request = new XMLHttpRequest();
??????????? } else {
??????????????? request = new ActiveXObject("Microsoft.XMLHTTP");
??????????? }
??????????? request.open("post", "jie", true);????????????????????????????? //向服務(wù)器發(fā)送請(qǐng)求
??????????? request.setRequestHeader("content-type","application/x-www-form-urlencoded");
??????????? request.send("name="+document.getElementById("ll").value+"");?????????? ?
??????????? request.onreadystatechange=function(){
????????????? if(request.readyState==4&&request.status==200){??????????????? //請(qǐng)求成功和響應(yīng)成功
???????????????? alert(request.responseText);?????????????????????????????? //得到數(shù)據(jù)
????????????? }
??????????? }
??????? }
?????? ?
??? </script>
jsp代碼:
??? public void doPost(HttpServletRequest request, HttpServletResponse response)
?? ??? ??? ?throws ServletException, IOException {
?? ??? ?request.setCharacterEncoding("utf-8");
??????? response.setCharacterEncoding("utf-8");
??????? PrintWriter out=response.getWriter();
??????? out.print("你好");
??????? out.flush();
??????? out.close();
?? ?}