第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

ajax請(qǐng)求導(dǎo)致頁(yè)面崩潰

ajax請(qǐng)求導(dǎo)致頁(yè)面崩潰

sntatas 2016-06-05 12:30:48
/** ?*?使用ajax提交表單,并接收返回值,根據(jù)返回值產(chǎn)生提示 ?*/ function?subForm(){ alert($("#basePath").val()); $.ajax({ url?:?$("#basePath").val()+"servlet/RegisterServlet", dataType?:?"text", data?:?{"username":$("#user").val(),"password":$("#pass").val(),"again":$("#again").val(),"captcha":$("#captcha")}, timeout?:?1000, type?:?"POST", success?:?function(data){ } }); }接收的Servlet代碼package?cn.edu.tjut.servlet; import?java.io.IOException; import?java.io.PrintWriter; import?javax.servlet.ServletException; import?javax.servlet.http.HttpServlet; import?javax.servlet.http.HttpServletRequest; import?javax.servlet.http.HttpServletResponse; import?cn.edu.tjut.service.RegisterService; public?class?RegisterServlet?extends?HttpServlet?{ public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ doPost(request,response); } public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ System.out.println("接收正常"); response.setContentType("text/html;charset=utf-8"); PrintWriter?pw?=?response.getWriter(); //從request中取出參數(shù) String?captcha?=?request.getParameter("captcha"); String?username?=?request.getParameter("username"); String?password?=?request.getParameter("password"); String?again?=?request.getParameter("again"); //獲取驗(yàn)證碼值 String?checkcode?=?(String)request.getSession().getAttribute("checkcode"); //驗(yàn)證驗(yàn)證碼是否正確 if(!captcha.equals(checkcode)){ pw.print(-1); pw.flush(); pw.close(); return; } //檢查兩次輸入密碼是否一致 if(!password.equals(again)){ pw.print(-2); pw.flush(); pw.close(); return; } RegisterService?rs?=?new?RegisterService(); int?res?=?rs.addUser(username,?password); //驗(yàn)證添加是否成功 if(res==0){ pw.print(0); pw.flush(); pw.close(); request.getRequestDispatcher("/login.jsp").forward(request,?response); } pw.print(res); pw.flush(); pw.close(); } }控制臺(tái)并沒有輸出接收正常
查看完整描述

3 回答

?
sntatas

TA貢獻(xiàn)53條經(jīng)驗(yàn) 獲得超11個(gè)贊

找到錯(cuò)誤了,參數(shù)格式錯(cuò)誤

$("captcha")應(yīng)該改為$("captcha").val()

查看完整回答
反對(duì) 回復(fù) 2016-11-21
?
sntatas

TA貢獻(xiàn)53條經(jīng)驗(yàn) 獲得超11個(gè)贊

使用原生的js原生的ajax能夠正常接收。

查看完整回答
反對(duì) 回復(fù) 2016-11-21
  • 3 回答
  • 0 關(guān)注
  • 2231 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)